use of org.apache.jena.ontology.OntModel in project ORCID-Source by ORCID.
the class RDFMessageBodyWriter method writeTo.
/**
* Write a type to an HTTP response. The response header map is mutable but
* any changes must be made before writing to the output stream since the
* headers will be flushed prior to writing the response body.
*
* @param message
* the instance to write.
* @param type
* the class of object that is to be written.
* @param genericType
* the type of object to be written, obtained either by
* reflection of a resource method return type or by inspection
* of the returned instance.
* {@link javax.ws.rs.core.GenericEntity} provides a way to
* specify this information at runtime.
* @param annotations
* an array of the annotations on the resource method that
* returns the object.
* @param mediaType
* the media type of the HTTP entity.
* @param httpHeaders
* a mutable map of the HTTP response headers.
* @param entityStream
* the {@link java.io.OutputStream} for the HTTP entity. The
* implementation should not close the output stream.
* @throws java.io.IOException
* if an IO error arises
* @throws javax.ws.rs.WebApplicationException
* if a specific HTTP error response needs to be produced. Only
* effective if thrown prior to the response being committed.
*/
@Override
public void writeTo(OrcidMessage xml, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
OntModel m = getOntModel();
if (xml.getErrorDesc() != null) {
describeError(xml.getErrorDesc(), m);
}
OrcidProfile orcidProfile = xml.getOrcidProfile();
// System.out.println(httpHeaders);
Individual profileDoc = null;
if (orcidProfile != null) {
Individual person = describePerson(orcidProfile, m);
if (person != null) {
profileDoc = describeAccount(orcidProfile, m, person);
}
}
MediaType jsonLd = new MediaType("application", "ld+json");
MediaType nTriples = new MediaType("application", "n-triples");
MediaType rdfXml = new MediaType("application", "rdf+xml");
String base = null;
if (getUriInfo() != null) {
getUriInfo().getAbsolutePath().toASCIIString();
}
if (mediaType.isCompatible(nTriples)) {
// NOTE: N-Triples requires absolute URIs
m.write(entityStream, "N-TRIPLES");
} else if (mediaType.isCompatible(jsonLd)) {
m.write(entityStream, "JSON-LD", base);
} else if (mediaType.isCompatible(rdfXml)) {
m.write(entityStream, "RDF/XML", base);
} else {
// Turtle is the safest default
m.write(entityStream, "TURTLE", base);
}
}
use of org.apache.jena.ontology.OntModel in project jena by apache.
the class JenaOSGITest method testJenaCore.
@Test
public void testJenaCore() throws Exception {
Model model = makeModel();
Writer writer = new StringWriter();
model.write(writer, "N-Triples");
assertEquals("<http://example.com/alice> <http://xmlns.com/foaf/0.1/knows> <http://example.com/bob> .", writer.toString().trim());
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
ObjectProperty knowsObjProp = ontModel.createObjectProperty(knows.getURI());
ObjectProperty hasFriend = ontModel.createObjectProperty("http://example.com/has_friend");
hasFriend.addSuperProperty(knowsObjProp);
Individual aliceIndividual = ontModel.createIndividual(alice);
Individual bobIndividiual = ontModel.createIndividual(bob);
ontModel.add(aliceIndividual, hasFriend, bobIndividiual);
assertTrue(aliceIndividual.hasProperty(knowsObjProp, bobIndividiual));
}
use of org.apache.jena.ontology.OntModel in project legato by DOREMUS-ANR.
the class ModelManager method loadModel.
/**
*************************************
***Load the RDF model from an RDF file
**************************************
*/
public static Model loadModel(String inputFile) {
Model model = ModelFactory.createDefaultModel();
try {
InputStream in = new FileInputStream(inputFile);
String ext = FilenameUtils.getExtension(inputFile);
if (ext.equals("nt")) {
model.read(in, null, "N-TRIPLES");
} else if (ext.equals("ttl")) {
model.read(in, null, "TTL");
} else if (ext.equals("rdf")) {
model.read(in, null, "RDF/XML");
} else if (ext.equals("owl")) {
OntModel ontologyModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
ontologyModel.read(in, "RDF/XML-ABBREV");
model = ontologyModel.getBaseModel();
}
} catch (Exception e) {
e.printStackTrace();
}
return model;
}
use of org.apache.jena.ontology.OntModel in project jena by apache.
the class TestFileManager method testFileManagerReadOntModel.
@Test
public void testFileManagerReadOntModel() {
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
FileManager.getInternal().readModelInternal(model, testingDir + "/data.ttl");
// Check
Individual ind = model.getIndividual("http://example.com/individual");
String t = ind.getOntClass().getURI();
assertEquals("http://example.com/T", t);
long c1 = model.size();
model.loadImports();
long c2 = model.size();
assertEquals(c1, c2);
}
use of org.apache.jena.ontology.OntModel in project jena by apache.
the class TestReasoners method testTransitiveCycleBug.
/**
* Cycle bug in transitive reasoner
*/
public void testTransitiveCycleBug() {
Model m = FileManager.getInternal().loadModelInternal("file:testing/reasoners/bugs/unbroken.n3");
OntModel om = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF, m);
OntClass rootClass = om.getOntClass(RDFS.Resource.getURI());
Resource c = m.getResource("c");
Set<OntClass> direct = rootClass.listSubClasses(true).toSet();
assertFalse(direct.contains(c));
}
Aggregations