use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class EnhancerUtils method addActiveChains.
/**
* Create the RDF data for the currently active Enhancement {@link Chain}s.<p>
* Note the the parsed rootUrl MUST already consider offsets configured
* for the Stanbol RESTful service. When called from within a
* {@link BaseStanbolResource} the following code segment should be used:<p>
* <code><pre>
* String rootUrl = uriInfo.getBaseUriBuilder().path(getRootUrl()).build().toString();
* </pre></code>
* @param activeChains the active enhancement chains as {@link Entry entries}.
* @param defaultChain the default chain
* @param graph the RDF graph to add the triples
* @param rootUrl the root URL used by the current request
*/
public static void addActiveChains(Iterable<Entry<ServiceReference, Chain>> activeChains, Chain defaultChain, Graph graph, String rootUrl) {
IRI enhancer = new IRI(rootUrl + "enhancer");
graph.add(new TripleImpl(enhancer, RDF.type, Enhancer.ENHANCER));
for (Entry<ServiceReference, Chain> entry : activeChains) {
IRI chainResource = new IRI(rootUrl + "enhancer/chain/" + entry.getValue().getName());
graph.add(new TripleImpl(enhancer, Enhancer.HAS_CHAIN, chainResource));
if (entry.getValue().equals(defaultChain)) {
graph.add(new TripleImpl(enhancer, Enhancer.HAS_DEFAULT_CHAIN, chainResource));
}
graph.add(new TripleImpl(chainResource, RDF.type, Enhancer.ENHANCEMENT_CHAIN));
graph.add(new TripleImpl(chainResource, RDFS.label, new PlainLiteralImpl(entry.getValue().getName())));
}
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class ContentItemReader method createParsedLanguageAnnotation.
/**
* Creates a fise:TextAnnotation for the explicitly parsed Content-Language
* header. The confidence of this annotation is set <code>1.0</code> (see
* <a href="https://issues.apache.org/jira/browse/STANBOL-1417">STANBOL-1417</a>).
* @param ci the {@link ContentItem} to the the language annotation
* @param lang the parsed language
*/
private void createParsedLanguageAnnotation(ContentItem ci, String lang) {
Graph m = ci.getMetadata();
IRI la = new IRI("urn:enhancement-" + EnhancementEngineHelper.randomUUID());
//add the fise:Enhancement information
m.add(new TripleImpl(la, RDF_TYPE, ENHANCER_ENHANCEMENT));
m.add(new TripleImpl(la, RDF_TYPE, ENHANCER_TEXTANNOTATION));
m.add(new TripleImpl(la, ENHANCER_EXTRACTED_FROM, ci.getUri()));
m.add(new TripleImpl(la, DC_CREATED, lf.createTypedLiteral(new Date())));
m.add(new TripleImpl(la, DC_CREATOR, lf.createTypedLiteral("Content-Language Header of the request")));
//add fise:TextAnnotation information as expected by a Language annotation.
m.add(new TripleImpl(la, DC_TYPE, DCTERMS_LINGUISTIC_SYSTEM));
m.add(new TripleImpl(la, DC_LANGUAGE, new PlainLiteralImpl(lang)));
//we set the confidence to 1.0^^xsd:double
m.add(new TripleImpl(la, ENHANCER_CONFIDENCE, lf.createTypedLiteral(Double.valueOf(1.0f))));
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class ContentItemBackendTest method testContentWithAdditionalMetadata.
@Test
public void testContentWithAdditionalMetadata() throws IOException, LDPathParseException {
byte[] content = "text content".getBytes();
IRI uri = ContentItemHelper.makeDefaultUrn(content);
ContentItem contentItem = ciFactory.createContentItem(uri, new ByteArraySource(content, "text/plain; charset=UTF-8"));
Graph tc = new SimpleGraph();
Literal literal = LiteralFactory.getInstance().createTypedLiteral("Michael Jackson");
IRI subject = new IRI("dummyUri");
tc.add(new TripleImpl(subject, new IRI("http://xmlns.com/foaf/0.1/givenName"), literal));
contentItem.addPart(new IRI(uri.getUnicodeString() + "_additionalMetadata"), tc);
ContentItemBackend ciBackend = new ContentItemBackend(contentItem, true);
LDPath<RDFTerm> ldPath = new LDPath<RDFTerm>(ciBackend, EnhancerLDPath.getConfig());
Collection<RDFTerm> result = ldPath.pathQuery(subject, "foaf:givenName", null);
assertTrue("Additional metadata cannot be found", result.contains(literal));
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class ContentItemTest method addingAndRetrieving.
@Test
public void addingAndRetrieving() throws IOException {
ContentItem ci = createContentItem(contentSource);
assertNotNull(ci);
assertNotNull(ci.getUri());
IRI partUri = new IRI("http://foo/");
Date someObject = new Date();
ci.addPart(partUri, someObject);
ci.getMetadata().add(new TripleImpl(ci.getUri(), new IRI("http://example.org/ontology#hasPart"), partUri));
ci.getMetadata().add(new TripleImpl(partUri, new IRI("http://example.org/ontology#isPartOf"), ci.getUri()));
assertEquals(someObject, ci.getPart(partUri, Date.class));
assertEquals(someObject, ci.getPart(1, Date.class));
assertEquals(partUri, ci.getPartUri(1));
assertEquals(new IRI(ci.getUri().getUnicodeString() + "_main"), ci.getPartUri(0));
try {
ci.getPart(2, Object.class);
assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
} catch (NoSuchPartException e) {
/* expected*/
}
try {
ci.getPart(new IRI("http://foo/nonexisting"), Object.class);
assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
} catch (NoSuchPartException e) {
/* expected*/
}
try {
ci.getPartUri(2);
assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
} catch (NoSuchPartException e) {
/* expected*/
}
//finally log the toString
log.info("toString: {}", ci);
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class MultipartRequestTest method getDummyRdfMetadata.
/**
* @param contentItemId
* @param rdfContentType
* @return
*/
private String getDummyRdfMetadata(final IRI contentItemId, String rdfContentType) {
Graph metadata = new SimpleGraph();
metadata.add(new TripleImpl(new BlankNode(), Properties.ENHANCER_EXTRACTED_FROM, contentItemId));
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.serialize(out, metadata, rdfContentType);
String rdfContent = new String(out.toByteArray(), UTF8);
return rdfContent;
}
Aggregations