use of com.hp.hpl.jena.rdf.model.Property in project stanbol by apache.
the class JenaReasoningServiceTest method testRunWithRules.
/**
* Tests the run(Model,List<Rule>) method of a service
*
* @param service
*/
private void testRunWithRules(JenaReasoningService service) {
// Prepare the rule set
String source = "" + "\n@prefix foaf: <" + TestData.FOAF_NS + ">." + "\n@prefix ex: <" + TestData.TEST_NS + ">." + "\n[rule1: (?a foaf:knows ?b) (?a foaf:workplaceHomepage ?w) (?b foaf:workplaceHomepage ?w) -> (?a ex:collegueOf ?b)] " + "\n[rule2: (?b foaf:knows ?a) -> (?a foaf:knows ?b)] " + "\n[rule3: (?a ex:collegueOf ?b) -> (?b ex:collegueOf ?a)] ";
// log.info("This is the ruleset: \n {}", source);
List<Rule> rules = TestUtils.parseRuleStringAsFile(source);
log.info("Loaded {} rules", rules.size());
// Clean data
TestData.alexdma.removeProperties();
TestData.enridaga.removeProperties();
Resource wphomepage = TestData.model.createResource("http://stlab.istc.cnr.it");
// Prepare data
TestData.alexdma.addProperty(TestData.foaf_knows, TestData.enridaga);
TestData.alexdma.addProperty(TestData.foaf_workplaceHomepage, wphomepage);
TestData.enridaga.addProperty(TestData.foaf_workplaceHomepage, wphomepage);
// Setup input for the reasoner
Model input = ModelFactory.createUnion(TestData.enridaga.getModel(), TestData.alexdma.getModel());
input = ModelFactory.createUnion(input, TestData.foaf);
// Run the method
Set<Statement> inferred = service.run(input, rules).listStatements().toSet();
// Expected statements
Property collegueOf = TestData.model.createProperty(TestData.TEST_NS + "collegueOf");
Set<Statement> expected = new HashSet<Statement>();
expected.add(TestData.model.createStatement(TestData.alexdma, collegueOf, TestData.enridaga));
expected.add(TestData.model.createStatement(TestData.enridaga, collegueOf, TestData.alexdma));
log.info("All the expected statements must be in the inferred output");
Set<Statement> notInOutput = TestUtils.expectedStatementsCheck(inferred, expected);
log.info("Are all expected statements in the inferred set (true)? {}", notInOutput.isEmpty());
if (!notInOutput.isEmpty()) {
for (Statement bad : notInOutput) {
log.error("The following statement is not included in the reasoner output: {}", bad);
}
}
assertTrue(notInOutput.isEmpty());
// Clean data
TestData.alexdma.removeProperties();
TestData.enridaga.removeProperties();
}
use of com.hp.hpl.jena.rdf.model.Property in project stanbol by apache.
the class JenaToClerezzaConverterTest method setupClass.
@BeforeClass
public static void setupClass() {
/*
* Set-up the Jena model for the test.
* Simply add the triples:
* AndreaNuzzolese isA Person
* EnricoDaga isA Person
* AndreaNuzzolese knows EnricoDaga
*/
model = ModelFactory.createDefaultModel();
Resource foafPersonInJena = model.createResource(foaf + "Person");
Property knowsInJena = model.createProperty(foaf + "knows");
Resource andreaNuzzoleseInJena = model.createResource(ns + "AndreaNuzzolese", foafPersonInJena);
Resource enricoDagaInJena = model.createResource(ns + "EnricoDaga", foafPersonInJena);
andreaNuzzoleseInJena.addProperty(knowsInJena, enricoDagaInJena);
/*
* Set-up the Clerezza model for the test.
* As before simply add the triples:
* AndreaNuzzolese isA Person
* EnricoDaga isA Person
* AndreaNuzzolese knows EnricoDaga
*/
mGraph = new SimpleGraph();
IRI knowsInClerezza = new IRI(ns + "knows");
IRI rdfType = new IRI(RDF.getURI() + "type");
IRI foafPersonInClerezza = new IRI(foaf + "Person");
BlankNodeOrIRI andreaNuzzoleseInClerezza = new IRI(ns + "AndreaNuzzolese");
BlankNodeOrIRI enricoDagaInClerezza = new IRI(ns + "EnricoDaga");
Triple triple = new TripleImpl(andreaNuzzoleseInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(enricoDagaInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(andreaNuzzoleseInClerezza, knowsInClerezza, enricoDagaInClerezza);
mGraph.add(triple);
}
use of com.hp.hpl.jena.rdf.model.Property in project stanbol by apache.
the class JenaRDFSReasoningServiceTest method testRDFSSubPropertyOf.
@Test
public void testRDFSSubPropertyOf() {
log.info("Testing rdfs:subPropertyOf inference with RDFS reasoner");
// We invent a property to extend foaf:knows
Property collegueOf = TestData.model.createProperty(TestData.TEST_NS + "collegueOf");
collegueOf.addProperty(RDFS.subPropertyOf, TestData.foaf_knows);
// Prepare data
TestData.alexdma.addProperty(collegueOf, TestData.enridaga);
// Setup input for the reasoner
Model input = ModelFactory.createUnion(TestData.foaf, TestData.alexdma.getModel());
// Does alexdma know enridaga?
InfModel inferred = reasoningService.run(input);
Statement knowsHim = TestData.model.createStatement(TestData.alexdma, TestData.foaf_knows, TestData.enridaga);
// log.info("Statements: {}", TestUtils.printStatements(inferred,
// TestData.enridaga, RDF.type));
log.info("Does alexdma foaf:knows enridaga?...(true)? {}", inferred.contains(knowsHim));
assertTrue(inferred.contains(knowsHim));
// Reset resource to be clean for other tests
TestData.alexdma.removeProperties();
}
use of com.hp.hpl.jena.rdf.model.Property in project wikidata-query-rdf by wikimedia.
the class BigdataStatementToJenaStatementMapper method map1.
@Override
public Statement map1(final BigdataStatement blzgStmt) {
final Resource s = convertToJenaResource(blzgStmt.getSubject());
final Property p = convertToJenaProperty(blzgStmt.getPredicate());
final RDFNode o = convertToJenaRDFNode(blzgStmt.getObject());
return ResourceFactory.createStatement(s, p, o);
}
use of com.hp.hpl.jena.rdf.model.Property in project eol-globi-data by jhpoelen.
the class StudyImporterForSaproxylic method importStudy.
@Override
public void importStudy() throws StudyImporterException {
try {
final Model model = ModelFactory.createDefaultModel();
NavigableSet<Triple<String, String, String>> triples = DBMaker.newTempTreeSet();
Tripler add = triple -> {
Resource resource = model.createResource("sx:" + triple.getLeft());
Property property = model.createProperty("sx:" + triple.getMiddle());
String obj = triple.getRight();
if (StringUtils.startsWith(obj, "{")) {
Resource food = model.createResource("sx:" + obj);
model.add(resource, property, food);
} else if (StringUtils.startsWith(obj, "http")) {
model.add(resource, property, model.createResource(obj));
} else if (StringUtils.isNotBlank(obj)) {
model.add(resource, property, obj);
}
};
parseReferences(add, getDataset().getResource("sx_txt/Reference.txt"));
parseLocalities(add, getDataset().getResource("sx_txt/Locality.txt"));
parseTaxa(add, getDataset().getResource("sx_txt/Taxon.txt"));
parseTaxonRanks(add, getDataset().getResource("sx_txt/TaxonRank.txt"));
parseOccurrences(add, getDataset().getResource("sx_txt/Occurrence.txt"));
parseAssociations(add, getDataset().getResource("sx_txt/SX_Association.txt"));
parseInteractionTypeMap(add, getDataset().getResource("interaction_type_map.tsv"));
// associations -> occurrences, taxa, reference
String queryString = "SELECT ?sourceTaxonName ?sourceLifeStage ?interactionTypeId ?targetTaxonName ?targetLifeStage ?referenceCitation ?localityName ?studyTitle " + "WHERE {" + " ?interaction <sx:mentioned_by> ?studyTitle . " + " ?studyTitle <sx:hasName> ?referenceCitation . " + " ?sourceSpecimen <sx:participates_in> ?interaction . " + " ?targetSpecimen <sx:participates_in> ?interaction . " + " ?sourceSpecimen ?inter ?targetSpecimen . " + " ?inter <sx:equivalentTo> ?interactionTypeId . " + " ?sourceSpecimen <sx:classifiedAs> ?sourceTaxon . " + " ?sourceTaxon <sx:hasName> ?sourceTaxonName . " + " ?targetSpecimen <sx:classifiedAs> ?targetTaxon . " + " ?targetTaxon <sx:hasName> ?targetTaxonName . " + " ?sourceSpecimen <sx:inStage> ?sourceLifeStage . " + " ?targetSpecimen <sx:inStage> ?targetLifeStage . " + " ?targetSpecimen <sx:foundAt> ?locality . " + " ?locality <sx:hasName> ?localityName . " + "}";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
toInteractions(results);
qe.close();
} catch (IOException e) {
throw new StudyImporterException("failed to access resource", e);
}
}
Aggregations