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!");
}
}
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));
}
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);
}
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);
}
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();
}
}
Aggregations