Search in sources :

Example 56 with PlainLiteralImpl

use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.

the class ExecutionMetadataHelper method setExecutionFaild.

/**
     * Set the parsed execution node to failed.
     * @param graph
     * @param execution
     * @param message An message describing why the execution failed
     */
public static void setExecutionFaild(Graph graph, BlankNodeOrIRI execution, String message) {
    Literal dateTime = lf.createTypedLiteral(new Date());
    setStatus(graph, execution, STATUS_FAILED);
    graph.add(new TripleImpl(execution, COMPLETED, dateTime));
    if (message != null) {
        graph.add(new TripleImpl(execution, STATUS_MESSAGE, new PlainLiteralImpl(message)));
    } else {
        throw new IllegalArgumentException("For faild Execution a STATUS message is required!");
    }
}
Also used : 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) Date(java.util.Date)

Example 57 with PlainLiteralImpl

use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.

the class DBPSpotlightSpotEnhancementTest method initTest.

@Before
public void initTest() throws IOException {
    //create the contentItem for testing
    ci = ciFactory.createContentItem(new StringSource(TEST_TEXT));
    assertNotNull(ci);
    textContentPart = ContentItemHelper.getBlob(ci, Collections.singleton("text/plain"));
    assertNotNull(textContentPart);
    //add the language of the text
    ci.getMetadata().add(new TripleImpl(ci.getUri(), Properties.DC_LANGUAGE, new PlainLiteralImpl("en")));
    assertEquals("en", EnhancementEngineHelper.getLanguage(ci));
}
Also used : PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) StringSource(org.apache.stanbol.enhancer.servicesapi.impl.StringSource) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Before(org.junit.Before)

Example 58 with PlainLiteralImpl

use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.

the class DBPSpotlightDisambiguateEnhancementTest method initTest.

@Before
public void initTest() throws IOException {
    //create the contentItem for testing
    ci = ciFactory.createContentItem(new StringSource(TEST_TEXT));
    assertNotNull(ci);
    textContentPart = ContentItemHelper.getBlob(ci, Collections.singleton("text/plain"));
    assertNotNull(textContentPart);
    //add the language of the text
    ci.getMetadata().add(new TripleImpl(ci.getUri(), Properties.DC_LANGUAGE, new PlainLiteralImpl("en")));
    assertEquals("en", EnhancementEngineHelper.getLanguage(ci));
    LiteralFactory lf = LiteralFactory.getInstance();
    //we need also to create a fise:TextAnnotation to test disambiguation
    String selected = "Angela Merkel";
    Language en = new Language("en");
    IRI textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, new DBPSpotlightSpotEnhancementEngine());
    Graph model = ci.getMetadata();
    model.add(new TripleImpl(textAnnotation, Properties.ENHANCER_SELECTED_TEXT, new PlainLiteralImpl(selected, en)));
    model.add(new TripleImpl(textAnnotation, Properties.ENHANCER_SELECTION_CONTEXT, new PlainLiteralImpl(TEST_TEXT, en)));
    model.add(new TripleImpl(textAnnotation, Properties.ENHANCER_START, lf.createTypedLiteral(TEST_TEXT.indexOf(selected))));
    model.add(new TripleImpl(textAnnotation, Properties.ENHANCER_END, lf.createTypedLiteral(TEST_TEXT.indexOf(selected) + selected.length())));
    model.add(new TripleImpl(textAnnotation, Properties.DC_TYPE, OntologicalClasses.DBPEDIA_PERSON));
    //validate that the created TextAnnotation is valid (test the test ...)
    EnhancementStructureHelper.validateAllTextAnnotations(model, TEST_TEXT, null);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) DBPSpotlightSpotEnhancementEngine(org.apache.stanbol.enhancer.engines.dbpspotlight.spot.DBPSpotlightSpotEnhancementEngine) Graph(org.apache.clerezza.commons.rdf.Graph) Language(org.apache.clerezza.commons.rdf.Language) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) StringSource(org.apache.stanbol.enhancer.servicesapi.impl.StringSource) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) LiteralFactory(org.apache.clerezza.rdf.core.LiteralFactory) Before(org.junit.Before)

Example 59 with PlainLiteralImpl

use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.

the class DereferenceEngineTest method setUpServices.

@BeforeClass
public static void setUpServices() throws IOException {
    testData = new IndexedGraph();
    long seed = System.currentTimeMillis();
    log.info("Test seed " + seed);
    Random random = new Random(seed);
    int numEntities = 0;
    for (int i = 0; i < NUM_ENTITIES; i++) {
        if (random.nextFloat() <= PERCENTAGE_PRESENT) {
            //do not create all entities
            IRI uri = new IRI("urn:test:entity" + i);
            testData.add(new TripleImpl(uri, RDF_TYPE, SKOS_CONCEPT));
            testData.add(new TripleImpl(uri, RDFS_LABEL, new PlainLiteralImpl("entity " + i, LANG_EN)));
            testData.add(new TripleImpl(uri, RDFS_LABEL, new PlainLiteralImpl("Entity " + i, LANG_DE)));
            testData.add(new TripleImpl(uri, SKOS_NOTATION, lf.createTypedLiteral(i)));
            numEntities++;
        }
    }
    log.info(" ... created {} Entities", numEntities);
    testMetadata = new IndexedGraph();
    int numLinks = 0;
    int numOtherLinks = 0;
    for (int i = 0; i < NUM_ENTITIES; i++) {
        float r = random.nextFloat();
        if (r < PERCENTAGE_LINKED) {
            IRI enhancementUri = new IRI("urn:test:enhancement" + i);
            IRI entityUri = new IRI("urn:test:entity" + i);
            //we do not need any other triple for testing in the contentItem
            testMetadata.add(new TripleImpl(enhancementUri, ENHANCER_ENTITY_REFERENCE, entityUri));
            numLinks++;
        } else if ((r - PERCENTAGE_LINKED) < PERCENTAGE_LINKED_OTHER) {
            IRI enhancementUri = new IRI("urn:test:enhancement" + i);
            IRI entityUri = new IRI("urn:test:entity" + i);
            //we do not need any other triple for testing in the contentItem
            testMetadata.add(new TripleImpl(enhancementUri, OTHER_ENTITY_REFERENCE, entityUri));
            numOtherLinks++;
        }
    }
    log.info("> created {} Entity references and {} references using an alternative proeprty ", numLinks, numOtherLinks);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Random(java.util.Random) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) BeforeClass(org.junit.BeforeClass)

Example 60 with PlainLiteralImpl

use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.

the class CeliLemmatizerEnhancementEngine method addMorphoAnalysisEnhancement.

private void addMorphoAnalysisEnhancement(ContentItem ci, String text, String language, Graph g) throws EngineException {
    // clerezza language for PlainLiterals
    Language lang = new Language(language);
    List<LexicalEntry> terms;
    try {
        terms = this.client.performMorfologicalAnalysis(text, language);
    } catch (IOException e) {
        throw new EngineException("Error while calling the CELI Lemmatizer" + " service (configured URL: " + serviceURL + ")!", e);
    } catch (SOAPException e) {
        throw new EngineException("Error wile encoding/decoding the request/" + "response to the CELI lemmatizer service!", e);
    }
    // get a write lock before writing the enhancements
    ci.getLock().writeLock().lock();
    try {
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        for (LexicalEntry le : terms) {
            List<CeliMorphoFeatures> mFeatures = this.convertLexicalEntryToMorphFeatures(le, language);
            for (CeliMorphoFeatures feat : mFeatures) {
                // Create a text annotation for each interpretation produced by the morphological analyzer
                IRI textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
                g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTED_TEXT, new PlainLiteralImpl(le.getWordForm(), lang)));
                if (le.from >= 0 && le.to > 0) {
                    g.add(new TripleImpl(textAnnotation, ENHANCER_START, literalFactory.createTypedLiteral(le.from)));
                    g.add(new TripleImpl(textAnnotation, ENHANCER_END, literalFactory.createTypedLiteral(le.to)));
                    g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTION_CONTEXT, new PlainLiteralImpl(getSelectionContext(text, le.getWordForm(), le.from), lang)));
                }
                g.addAll(feat.featuresAsTriples(textAnnotation, lang));
            }
        }
    } finally {
        ci.getLock().writeLock().unlock();
    }
}
Also used : CeliMorphoFeatures(org.apache.stanbol.enhancer.engines.celi.CeliMorphoFeatures) IRI(org.apache.clerezza.commons.rdf.IRI) Language(org.apache.clerezza.commons.rdf.Language) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) SOAPException(javax.xml.soap.SOAPException) EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) IOException(java.io.IOException) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) LiteralFactory(org.apache.clerezza.rdf.core.LiteralFactory)

Aggregations

PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)82 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)69 IRI (org.apache.clerezza.commons.rdf.IRI)58 Graph (org.apache.clerezza.commons.rdf.Graph)34 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)20 Language (org.apache.clerezza.commons.rdf.Language)19 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)18 Literal (org.apache.clerezza.commons.rdf.Literal)16 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)16 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Triple (org.apache.clerezza.commons.rdf.Triple)12 StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)12 ArrayList (java.util.ArrayList)11 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)11 LiteralFactory (org.apache.clerezza.rdf.core.LiteralFactory)10 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)10 Test (org.junit.Test)10 HashSet (java.util.HashSet)8 SOAPException (javax.xml.soap.SOAPException)6