Search in sources :

Example 61 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class DereferenceEngineConfig method parseEntityReferences.

/**
 * Parses the URIs for the {@link DereferenceConstants#ENTITY_REFERENCE_PROPERTIES}
 * @return
 * @throws ConfigurationException
 */
private Set<IRI> parseEntityReferences() throws ConfigurationException {
    Set<IRI> entityRefPropUris;
    Collection<String> entityProps = EnhancementEngineHelper.getConfigValues(config, ENTITY_REFERENCES, String.class);
    if (entityProps == null || entityProps.isEmpty()) {
        entityRefPropUris = DEFAULT_ENTITY_REFERENCES;
    } else {
        entityRefPropUris = new HashSet<IRI>(entityProps.size());
        for (String prop : entityProps) {
            if (!StringUtils.isBlank(prop)) {
                entityRefPropUris.add(new IRI(getConfiguredUri(nsPrefixService, ENTITY_REFERENCES, prop.trim())));
            }
        }
    }
    return entityRefPropUris;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI)

Example 62 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class DereferenceEngineTest method validateDereferencedEntities.

private void validateDereferencedEntities(Graph metadata, IRI... entityReferenceFields) {
    Graph expected = new IndexedGraph();
    for (IRI entityReferenceField : entityReferenceFields) {
        Iterator<Triple> referenced = metadata.filter(null, entityReferenceField, null);
        while (referenced.hasNext()) {
            IRI entity = (IRI) referenced.next().getObject();
            Iterator<Triple> entityTriples = testData.filter(entity, null, null);
            while (entityTriples.hasNext()) {
                expected.add(entityTriples.next());
            }
        }
    }
    Graph notExpected = new IndexedGraph(testData);
    notExpected.removeAll(expected);
    Assert.assertTrue(metadata.containsAll(expected));
    Assert.assertTrue(Collections.disjoint(metadata, notExpected));
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Example 63 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class SpotlightEngineUtils method createEntityAnnotation.

/**
 * Creates a fise:EntityAnnotation for the parsed parameters and
 * adds it the the {@link ContentItem#getMetadata()}. <p>
 * This method assumes a write lock on the parsed content item.
 * @param resource the candidate resource
 * @param engine the engine
 * @param ci the content item
 * @param textAnnotation the fise:TextAnnotation to dc:relate the
 * created fise:EntityAnnotation
 * @return the URI of the created fise:TextAnnotation
 */
public static IRI createEntityAnnotation(CandidateResource resource, EnhancementEngine engine, ContentItem ci, IRI textAnnotation) {
    IRI entityAnnotation = EnhancementEngineHelper.createEntityEnhancement(ci, engine);
    Graph model = ci.getMetadata();
    Literal label = new PlainLiteralImpl(resource.label, new Language("en"));
    model.add(new TripleImpl(entityAnnotation, DC_RELATION, textAnnotation));
    model.add(new TripleImpl(entityAnnotation, ENHANCER_ENTITY_LABEL, label));
    model.add(new TripleImpl(entityAnnotation, ENHANCER_ENTITY_REFERENCE, resource.getUri()));
    model.add(new TripleImpl(entityAnnotation, PROPERTY_CONTEXTUAL_SCORE, literalFactory.createTypedLiteral(resource.contextualScore)));
    model.add(new TripleImpl(entityAnnotation, PROPERTY_PERCENTAGE_OF_SECOND_RANK, literalFactory.createTypedLiteral(resource.percentageOfSecondRank)));
    model.add(new TripleImpl(entityAnnotation, PROPERTY_SUPPORT, literalFactory.createTypedLiteral(resource.support)));
    model.add(new TripleImpl(entityAnnotation, PROPERTY_PRIOR_SCORE, literalFactory.createTypedLiteral(resource.priorScore)));
    model.add(new TripleImpl(entityAnnotation, PROPERTY_FINAL_SCORE, literalFactory.createTypedLiteral(resource.finalScore)));
    return entityAnnotation;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) Language(org.apache.clerezza.commons.rdf.Language) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) Literal(org.apache.clerezza.commons.rdf.Literal) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Example 64 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class ContentItemResource method getPlacesAsJSON.

/**
 * @return an RDF/JSON descriptions of places for the word map widget
 */
public String getPlacesAsJSON() throws ParseException, UnsupportedEncodingException {
    Graph g = new IndexedGraph();
    LiteralFactory lf = LiteralFactory.getInstance();
    Graph metadata = contentItem.getMetadata();
    for (EntityExtractionSummary p : getPlaceOccurrences()) {
        EntitySuggestion bestGuess = p.getBestGuess();
        if (bestGuess == null) {
            continue;
        }
        IRI uri = new IRI(bestGuess.getUri());
        Iterator<Triple> latitudes = metadata.filter(uri, GEO_LAT, null);
        if (latitudes.hasNext()) {
            g.add(latitudes.next());
        }
        Iterator<Triple> longitutes = metadata.filter(uri, GEO_LONG, null);
        if (longitutes.hasNext()) {
            g.add(longitutes.next());
            g.add(new TripleImpl(uri, Properties.RDFS_LABEL, lf.createTypedLiteral(bestGuess.getLabel())));
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    serializer.serialize(out, g, SupportedFormat.RDF_JSON);
    String rdfString = out.toString("utf-8");
    return rdfString;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EnhancementEngineHelper.getString(org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.getString) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) LiteralFactory(org.apache.clerezza.rdf.core.LiteralFactory)

Example 65 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class ContentItemReaderWriterTest method createTestContentItem.

/**
 * @return
 */
@BeforeClass
public static void createTestContentItem() throws IOException {
    contentItem = ciFactory.createContentItem(new IRI("urn:test"), new StringSource("<html>\n" + "  <body>\n" + "    This is a <b>ContentItem</b> to <i>Mime Multipart</i> test!\n" + "  </body>\n" + "</html>", "text/html"));
    RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
    contentItem.addPart(new IRI("run:text:text"), ciFactory.createBlob(new StringSource("This is a ContentItem to Mime Multipart test!")));
    contentItem.getMetadata().add(new TripleImpl(new IRI("urn:test"), RDF.type, new IRI("urn:types:Document")));
    // mark the main content as parsed and also that all
    // contents and contentparts should be included
    Map<String, Object> properties = initRequestPropertiesContentPart(contentItem);
    properties.put(PARSED_CONTENT_URIS, Collections.singleton(contentItem.getPartUri(0).getUnicodeString()));
    properties.put(OUTPUT_CONTENT, Collections.singleton("*/*"));
    properties.put(OUTPUT_CONTENT_PART, Collections.singleton("*"));
    properties.put(RDF_FORMAT, "application/rdf+xml");
    Graph em = initExecutionMetadataContentPart(contentItem);
    BlankNodeOrIRI ep = createExecutionPlan(em, "testChain", null);
    writeExecutionNode(em, ep, "testEngine", true, null, null);
    initExecutionMetadata(em, em, contentItem.getUri(), "testChain", false);
    ciWriter = new ContentItemWriter(Serializer.getInstance());
    ciReader = new ContentItemReader() {

        @Override
        protected Parser getParser() {
            return Parser.getInstance();
        }

        @Override
        protected ContentItemFactory getContentItemFactory() {
            return ciFactory;
        }
    };
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) ContentItemFactory(org.apache.stanbol.enhancer.servicesapi.ContentItemFactory) InMemoryContentItemFactory(org.apache.stanbol.enhancer.contentitem.inmemory.InMemoryContentItemFactory) RuntimeDelegateImpl(org.glassfish.jersey.internal.RuntimeDelegateImpl) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Parser(org.apache.clerezza.rdf.core.serializedform.Parser) ContentItemReader(org.apache.stanbol.enhancer.jersey.reader.ContentItemReader) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) StringSource(org.apache.stanbol.enhancer.servicesapi.impl.StringSource) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ContentItemWriter(org.apache.stanbol.enhancer.jersey.writers.ContentItemWriter) BeforeClass(org.junit.BeforeClass)

Aggregations

IRI (org.apache.clerezza.commons.rdf.IRI)346 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)113 Graph (org.apache.clerezza.commons.rdf.Graph)109 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)104 Triple (org.apache.clerezza.commons.rdf.Triple)88 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)84 Test (org.junit.Test)78 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)58 HashSet (java.util.HashSet)50 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)46 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)37 ArrayList (java.util.ArrayList)37 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)36 Literal (org.apache.clerezza.commons.rdf.Literal)35 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)31 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)29 Recipe (org.apache.stanbol.rules.base.api.Recipe)29 Language (org.apache.clerezza.commons.rdf.Language)24