Search in sources :

Example 76 with TripleImpl

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())));
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Chain(org.apache.stanbol.enhancer.servicesapi.Chain) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ServiceReference(org.osgi.framework.ServiceReference)

Example 77 with TripleImpl

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))));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Date(java.util.Date)

Example 78 with TripleImpl

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));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) LDPath(org.apache.marmotta.ldpath.LDPath) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Literal(org.apache.clerezza.commons.rdf.Literal) ContentItemBackend(org.apache.stanbol.enhancer.ldpath.backend.ContentItemBackend) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) ByteArraySource(org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource) Test(org.junit.Test)

Example 79 with TripleImpl

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);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) NoSuchPartException(org.apache.stanbol.enhancer.servicesapi.NoSuchPartException) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Date(java.util.Date) Test(org.junit.Test)

Example 80 with TripleImpl

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;
}
Also used : SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNode(org.apache.clerezza.commons.rdf.BlankNode) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)143 IRI (org.apache.clerezza.commons.rdf.IRI)104 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)69 Graph (org.apache.clerezza.commons.rdf.Graph)66 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)49 Triple (org.apache.clerezza.commons.rdf.Triple)41 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)26 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)23 HashMap (java.util.HashMap)20 Language (org.apache.clerezza.commons.rdf.Language)20 Literal (org.apache.clerezza.commons.rdf.Literal)20 LiteralFactory (org.apache.clerezza.rdf.core.LiteralFactory)20 IOException (java.io.IOException)18 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)17 Test (org.junit.Test)16 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)15 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)14 HashSet (java.util.HashSet)13 StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)13 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)11