use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class RDFFilesLoader method loadEveryTimeFiles.
/**
* Load the "every time" files.
*
* The location is based on the home directory and the model path: "abox",
* "display", etc.
*
* The files from the directory become a sub-model of the model.
*/
public static void loadEveryTimeFiles(String modelPath, OntModel model) {
OntModel everytimeModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
String home = locateHomeDirectory();
Set<Path> paths = getPaths(home, RDF, modelPath, EVERY_TIME);
for (Path p : paths) {
log.info("Loading " + relativePath(p, home));
readOntologyFileIntoModel(p, everytimeModel);
}
model.addSubModel(everytimeModel);
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class UpdateKnowledgeBase method replaceTboxAndDisplayMetadata.
// replace
private void replaceTboxAndDisplayMetadata(OntModel displayModel, Model addStatements, Model removeStatements, UpdateSettings settings) {
OntModel oldDisplayModelTboxModel = settings.getOldDisplayModelTboxModel();
OntModel oldDisplayModelDisplayMetadataModel = settings.getOldDisplayModelDisplayMetadataModel();
OntModel newDisplayModelTboxModel = settings.getNewDisplayModelTboxModel();
OntModel newDisplayModelDisplayMetadataModel = settings.getNewDisplayModelDisplayMetadataModel();
OntModel loadedAtStartup = settings.getLoadedAtStartupDisplayModel();
OntModel oldVivoListView = settings.getVivoListViewConfigDisplayModel();
// Remove old display model tbox and display metadata statements from display model
removeStatements.add(oldDisplayModelTboxModel);
removeStatements.add(oldDisplayModelDisplayMetadataModel);
// the old startup folder only contained by oldVivoListView
removeStatements.add(oldVivoListView);
StringWriter sw = new StringWriter();
try {
log.debug("Adding old display tbox model, display metadata model, and oldVivoListView to remove statements. Remove statements now include:");
removeStatements.write(sw, "N3");
log.debug(sw.toString());
sw.close();
} catch (Exception ex) {
log.error("Exception occurred", ex);
}
// Add statements from new tbox and display metadata
addStatements.add(newDisplayModelTboxModel);
addStatements.add(newDisplayModelDisplayMetadataModel);
// this should include the list view in addition to other files
addStatements.add(loadedAtStartup);
try {
sw = new StringWriter();
log.debug("Adding new display tbox model, display metadata model, and loaded at startup to add statements. Add statements now include:");
addStatements.write(sw, "N3");
log.debug(sw.toString());
sw.close();
} catch (Exception ex) {
log.error("Exception occurred in adding new display model tbox/metadata info to add statements ", ex);
}
log.debug("Adding new display tbox model, display metadata model, and all models loaded at startup");
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class UpdateKnowledgeBase method loadModelFromFile.
// load file from file path
private OntModel loadModelFromFile(String filePath) {
log.debug("Load model from file " + filePath);
OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
File file = new File(filePath);
if (!file.isFile()) {
throw new ModelFileNotFoundException(filePath + " must be a file " + "containing RDF files.");
}
readFile(file, om, filePath);
return om;
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class UpdateKnowledgeBase method updateDataGetterLabels.
// update any new labels
private void updateDataGetterLabels(OntModel displayModel, Model addStatements, Model removeStatements, UpdateSettings settings) {
log.debug("Checking: BEFORE adding any statements, what do we have for pageList page");
Resource testResource = ResourceFactory.createResource(DisplayVocabulary.DISPLAY_NS + "pageListPage");
StmtIterator testIt = addStatements.listStatements(testResource, null, (RDFNode) null);
if (!testIt.hasNext()) {
log.debug("Add statements does not have the page list page resource " + testResource.getURI());
}
while (testIt.hasNext()) {
log.debug("Statement for page list resource: " + testIt.nextStatement().toString());
}
log.debug("Triple checking -- before this method, the add statements model contains");
StringWriter sw = new StringWriter();
try {
addStatements.write(sw, "N3");
log.debug(sw.toString());
sw.close();
} catch (Exception ex) {
log.error("Error occurred in adding resource labels ", ex);
}
OntModel newDisplayModel = settings.getNewDisplayModelFromFile();
List<Resource> resourcesForLabels = new ArrayList<Resource>();
resourcesForLabels.add(ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData"));
resourcesForLabels.add(ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.BrowseDataGetter"));
resourcesForLabels.add(ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter"));
resourcesForLabels.add(ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.InternalClassesDataGetter"));
resourcesForLabels.add(ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter"));
for (Resource r : resourcesForLabels) {
log.debug("Adding the following for " + r.getURI());
log.debug(newDisplayModel.listStatements(r, RDFS.label, (RDFNode) null).toList().toString());
addStatements.add(newDisplayModel.listStatements(r, RDFS.label, (RDFNode) null));
log.debug("After adding statements, we now have the following in addStatements:::");
sw = new StringWriter();
try {
addStatements.write(sw, "N3");
log.debug(sw.toString());
sw.close();
} catch (Exception ex) {
log.error("Error occurred in adding resource labels ", ex);
}
}
// Add statements now includes
log.debug("AFTER all resources added, Add statements now includes ");
sw = new StringWriter();
try {
addStatements.write(sw, "N3");
log.debug(sw.toString());
sw.close();
} catch (Exception ex) {
log.error("Error occurred in adding resource labels ", ex);
}
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class SimpleReasonerSameAsTest method mostSpecificTypeTest1.
/*
* test that mostSpecificType inferences propagate to sameAs
* individuals
*/
@Test
public void mostSpecificTypeTest1() {
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
OntClass classD = createClass(tBox, "http://test.vivo/D", "class D");
OntClass classE = createClass(tBox, "http://test.vivo/E", "class E");
// A is superclass of C, C is superclass of D and E
addSubclass(classA, classC);
addSubclass(classC, classD);
addSubclass(classC, classE);
// SimpleReasonerTBoxListener is not being used.
AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI);
// this will receive the abox inferences
Model inf = ModelFactory.createDefaultModel();
// abox
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
// set up SimpleReasoner and register it with abox
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
aBox.register(simpleReasoner);
// add & remove ABox type statements and verify inferences
Resource a = aBox.createResource("http://test.vivo/a");
Resource b = aBox.createResource("http://test.vivo/b");
Resource c = aBox.createResource("http://test.vivo/c");
Resource d = aBox.createResource("http://test.vivo/d");
// Assert a, b, c and d are the same
aBox.add(a, OWL.sameAs, b);
aBox.add(c, OWL.sameAs, b);
aBox.add(d, OWL.sameAs, a);
// Assert a is D, and d ic C
// All resources will therefore be C and D
aBox.add(a, RDF.type, classD);
aBox.add(d, RDF.type, classC);
// All resources should be inferred as C and D, except a and d which have direct assertions
// D is asserted for a
Assert.assertFalse(inf.contains(a, RDF.type, classD));
Assert.assertTrue(inf.contains(a, RDF.type, classC));
Assert.assertTrue(inf.contains(b, RDF.type, classD));
Assert.assertTrue(inf.contains(b, RDF.type, classC));
Assert.assertTrue(inf.contains(c, RDF.type, classD));
Assert.assertTrue(inf.contains(c, RDF.type, classC));
Assert.assertTrue(inf.contains(d, RDF.type, classD));
// C is asserted for d
Assert.assertFalse(inf.contains(d, RDF.type, classC));
// In all cases, mostSpecificType should be D, not C
Assert.assertTrue(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertTrue(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertTrue(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertTrue(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertFalse(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertFalse(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertFalse(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertFalse(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
aBox.remove(a, RDF.type, classD);
Assert.assertFalse(inf.contains(a, RDF.type, classD));
Assert.assertTrue(inf.contains(a, RDF.type, classC));
Assert.assertFalse(inf.contains(b, RDF.type, classD));
Assert.assertTrue(inf.contains(b, RDF.type, classC));
Assert.assertFalse(inf.contains(c, RDF.type, classD));
Assert.assertTrue(inf.contains(c, RDF.type, classC));
Assert.assertFalse(inf.contains(d, RDF.type, classD));
Assert.assertFalse(inf.contains(d, RDF.type, classC));
Assert.assertTrue(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertTrue(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertTrue(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertTrue(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertFalse(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertFalse(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertFalse(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertFalse(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
}
Aggregations