Skip to content

Commit

Permalink
Also implement finding all owl:equivalentClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Jul 2, 2012
1 parent b90fc5d commit e0f8513
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Expand Up @@ -267,6 +267,15 @@ public void addPrefix(IRDFStore store, String prefix, String namespace)
@TestMethods("testAllPredicates")
public List<String> allPredicates(IRDFStore store) throws BioclipseException;

@Recorded
@PublishedMethod(
params = "IRDFStore store, String resourceURI",
methodSummary = "Lists all resources that are owl:equivalentClass as the " +
"given resource."
)
public List<String> allOwlEquivalentClass(IRDFStore store, String resourceURI)
throws IOException, BioclipseException, CoreException;

@Recorded
@PublishedMethod(
params = "IRDFStore store, String resourceURI",
Expand Down
Expand Up @@ -543,6 +543,35 @@ public List<String> allOwlSameAs(IRDFStore store, String resourceURI)
return finalList;
}

public List<String> allOwlEquivalentClass(IRDFStore store, String resourceURI)
throws IOException, BioclipseException, CoreException {
Set<String> resources = new HashSet<String>();
resources.add(resourceURI);
// implements a non-reasoning owl:equivalentClass reasoner:
// keep looking up equivalentClass relations, until we find no new ones
List<String> newLeads = allOwlEquivalentClassOneDown(store, resourceURI);
newLeads.removeAll(resources); //
while (newLeads.size() > 0) {
List<String> newResources = new ArrayList<String>();
for (String resource : newLeads) {
System.out.println("Trying: " + resource);
if (!resources.contains(resource)) {
System.out.println("New: " + resource);
resources.add(resource);
newResources.addAll(
allOwlEquivalentClassOneDown(store, resource)
);
}
}
newResources.removeAll(resources);
newLeads = newResources;
}
List<String> finalList = new ArrayList<String>();
finalList.addAll(resources);
finalList.remove(resourceURI); // remove the source resource
return finalList;
}

public List<String> allOwlSameAsOneDown(IRDFStore store, String resourceURI)
throws IOException, BioclipseException, CoreException {
// got no reasoner, so need implement inverse relation manually
Expand All @@ -564,4 +593,26 @@ public List<String> allOwlSameAsOneDown(IRDFStore store, String resourceURI)
resources.addAll(results.getColumn("resource"));
return resources;
}

public List<String> allOwlEquivalentClassOneDown(IRDFStore store, String resourceURI)
throws IOException, BioclipseException, CoreException {
// got no reasoner, so need implement inverse relation manually
String sparql =
"PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
"SELECT ?resource WHERE {" +
" <" + resourceURI + "> owl:equivalentClass ?resource ." +
"}";
StringMatrix results = sparql(store, sparql);
if (results.getRowCount() == 0) return Collections.emptyList();
List<String> resources = results.getColumn("resource");
sparql =
"PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
"SELECT ?resource WHERE {" +
" ?resource owl:equivalentClass <" + resourceURI + ">." +
"}";
results = sparql(store, sparql);
if (results.getRowCount() == 0) return resources;
resources.addAll(results.getColumn("resource"));
return resources;
}
}

0 comments on commit e0f8513

Please sign in to comment.