Skip to content

Commit

Permalink
Start implementing the match functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fvilla committed Dec 4, 2024
1 parent 192d12d commit 05ee1b5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ public void run() {

var current = new ArrayList<String>();
for (var token : arguments) {
if (token.equals(",")) {
if (token.endsWith(",")) {
if (token.trim().length() > 1) {
current.add(token.trim().substring(0, token.length()-1));
}
tokens.add(current);
current = new ArrayList<>();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ interface REASONER {

String NEGATED = REASONER_BASE + "/negated";

String MATCHES = REASONER_BASE + "/matches";

String RELATIONSHIP_TARGETS = REASONER_BASE + "/relationshipTargets";

String SATISFIABLE = REASONER_BASE + "/satisfiable";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ public Collection<Concept> created(Semantics semantics) {

@Override
public boolean match(Semantics candidate, Semantics pattern) {
return false;
return client.post(ServicesAPI.REASONER.MATCHES, List.of(candidate.asConcept(),
pattern.asConcept()), Boolean.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public boolean subsumes(@RequestBody Concept[] concepts) {
return reasoner.klabService().subsumes(concepts[0], concepts[1]);
}

/**
* POST /matches
*
* @param concepts
* @return
*/
@PostMapping(ServicesAPI.REASONER.MATCHES)
public boolean matches(@RequestBody Concept[] concepts) {
return reasoner.klabService().match(concepts[0], concepts[1]);
}


/**
* POST /operands
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1783,8 +1783,7 @@ public Collection<Concept> created(Semantics semantics) {

@Override
public boolean match(Semantics candidate, Semantics pattern) {
// FIXME definitely not the same thing!
return compatible(candidate, pattern);
return syntacticMatcher.match(candidate, pattern);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public SyntacticMatcher(ReasonerService reasonerService, ResourcesService resour

public boolean match(Semantics candidate, Semantics pattern) {

if (isAtomic(pattern.getUrn())) {
return reasonerService.subsumes(candidate, pattern);
}

KimConcept oCandidate = null;
KimConcept pCandidate = null;

Expand All @@ -54,11 +58,12 @@ public boolean match(Semantics candidate, Semantics pattern) {
return false;
}

return matchConcepts (oCandidate, pCandidate);
return matchConcepts(oCandidate, pCandidate);
}

private boolean matchConcepts(KimConcept candidate, KimConcept pattern) {


if (pattern.is(SemanticType.UNION) || pattern.is(SemanticType.INTERSECTION)) {
// must have same type and same number of arguments
// TODO this applies also to all ops
Expand All @@ -75,4 +80,10 @@ private boolean matchConcepts(KimConcept candidate, KimConcept pattern) {

}

private boolean isAtomic(String urn) {
// TODO we should use a more intelligent check, although this one should work in all circumstances
// given that the URN is normalized.
return !urn.contains(" ");
}

}

0 comments on commit 05ee1b5

Please sign in to comment.