use of com.hp.hpl.jena.rdf.model.Statement in project stanbol by apache.
the class ConversionTester method testResourceJenaToOwlAxiom.
public void testResourceJenaToOwlAxiom() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OntModel model = ModelFactory.createOntologyModel();
OntClass jenaclass = model.createClass(CLAZZ.toString());
ObjectProperty jenaobprop = model.createObjectProperty(OP.toString());
DatatypeProperty jenadataprop = model.createDatatypeProperty(DP.toString());
Individual jenasub = model.createIndividual(SUBJECT.toString(), jenaclass);
Individual jenaobj = model.createIndividual(OBJECT.toString(), jenaclass);
AnnotationProperty jenaanno = model.createAnnotationProperty(label.toString());
Literal value = model.createTypedLiteral(VALUE, DATATYPE.toString());
model.add(jenasub, jenaobprop, jenaobj);
model.add(jenasub, jenadataprop, value);
model.add(jenasub, jenaanno, "Lucy", "en");
Set<OWLAxiom> owlaxiom = null;
try {
owlaxiom = j2o.ResourceJenaToOwlAxiom(jenasub, RDFXML);
if (owlaxiom == null) {
fail("Some errors occur");
} else {
StmtIterator str = model.listStatements();
int count = 0;
while (str.hasNext()) {
Statement stm = str.next();
Resource subject = stm.getSubject();
if (SUBJECT.toString().equals(subject.getURI()))
count++;
}
if (count == owlaxiom.size()) {
assertEquals(count, owlaxiom.size());
} else {
fail("The number of axioms don't match the number of statement");
}
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(owlaxiom);
}
}
use of com.hp.hpl.jena.rdf.model.Statement in project stanbol by apache.
the class JenaToClerezzaConverterTest method testGraphToJenaModel.
@Test
public void testGraphToJenaModel() {
/*
* Convert the Graph to a Jena Model.
*/
Model model = JenaToClerezzaConverter.clerezzaGraphToJenaModel(mGraph);
/*
* Print all the triples contained in the Jena Model.
*/
StmtIterator stmtIt = model.listStatements();
while (stmtIt.hasNext()) {
Statement statement = stmtIt.next();
log.info(statement.toString());
}
}
use of com.hp.hpl.jena.rdf.model.Statement in project stanbol by apache.
the class AbstractJenaReasoningService method prune.
/**
* Removes the statements in the first set from the second set
*
* @param input
* @param statements
* @return
*/
protected final Set<Statement> prune(Set<Statement> first, Set<Statement> second) {
log.debug(" prune(Set<Statement> first[{}], Set<Statement> second[{}])", first.size(), second.size());
Set<Statement> remove = new HashSet<Statement>();
for (Statement s : second) {
if (first.contains(s)) {
remove.add(s);
}
}
log.debug(" ---- removing {} statements from {}", first.size(), second.size());
second.removeAll(remove);
return second;
}
use of com.hp.hpl.jena.rdf.model.Statement in project stanbol by apache.
the class JenaReasoningServiceTest method testEnrich2.
/**
* Tests the enrich(Model data,boolean filtered) method
*
* @param service
*/
private void testEnrich2(JenaReasoningService service) {
// Clean data
TestData.alexdma.removeProperties();
// Prepare data
TestData.alexdma.addProperty(RDF.type, TestData.foaf_Person);
// Setup input for the reasoner
Model input = ModelFactory.createUnion(TestData.foaf, TestData.alexdma.getModel());
try {
// Run the method
Set<Statement> inferred = service.runTask(ReasoningService.Tasks.ENRICH, input, null, false, null);
// Prepare the input statements to check the output with
Set<Statement> inputStatements = input.listStatements().toSet();
log.info("All the input statements must be in the inferred output");
Set<Statement> notInOutput = new HashSet<Statement>();
for (Statement stat : inputStatements) {
if (!inferred.contains(stat)) {
notInOutput.add(stat);
}
}
log.info("Are all input statements in the inferred set (true)? {}", notInOutput.isEmpty());
if (!notInOutput.isEmpty()) {
for (Statement bad : notInOutput) {
log.error("Found a statement not included in output: {}", bad);
}
}
assertTrue(notInOutput.isEmpty());
} catch (ReasoningServiceException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
}
// Clean data
TestData.alexdma.removeProperties();
}
use of com.hp.hpl.jena.rdf.model.Statement in project stanbol by apache.
the class JenaReasoningServiceTest method testClassify.
/**
* Tests the classify() method
*/
private void testClassify(JenaReasoningService reasoningService) {
// Clean data
TestData.alexdma.removeProperties();
// Prepare data
TestData.alexdma.addProperty(RDF.type, TestData.foaf_Person);
// Setup input for the reasoner
Model input = ModelFactory.createUnion(TestData.foaf, TestData.alexdma.getModel());
// Run the method
Set<Statement> inferred;
try {
inferred = reasoningService.runTask(ReasoningService.Tasks.CLASSIFY, input);
boolean foafAgentExists = false;
log.info("Check for statements to be rdf:type only");
for (Statement stat : inferred) {
// Here we want only rdf:type statements
if (!stat.getPredicate().equals(RDF.type)) {
log.error("This statement is not rdf:type: {}", stat);
}
assertTrue(stat.getPredicate().equals(RDF.type));
if (stat.getObject().isResource()) {
if (stat.getObject().asResource().equals(TestData.foaf_Agent)) {
foafAgentExists = true;
}
}
}
log.info("Does the statement: example:me rdf:type foaf:Agent exists (true)? {}", foafAgentExists);
assertTrue(foafAgentExists);
} catch (ReasoningServiceException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
}
// Clean data
TestData.alexdma.removeProperties();
}
Aggregations