use of org.apache.stanbol.enhancer.servicesapi.rdf.NamespaceEnum in project stanbol by apache.
the class EnhancerLDPath method getConfig.
/**
* The LDPath configuration including the <ul>
* <li> Namespaces defined by the {@link NamespaceEnum}
* <li> the LDPath functions for the Stanbol Enhancement Structure
* </ul>
* @return the LDPath configuration for the Stanbol Enhancer
*/
public static final Configuration<RDFTerm> getConfig() {
if (CONFIG == null) {
CONFIG = new DefaultConfiguration<RDFTerm>();
//add the namespaces
for (NamespaceEnum ns : NamespaceEnum.values()) {
CONFIG.addNamespace(ns.getPrefix(), ns.getNamespace());
}
//now add the functions
addFunction(CONFIG, new ContentFunction());
String path;
NodeSelector<RDFTerm> selector;
//TextAnnotations
path = String.format("^%s[%s is %s]", ENHANCER_EXTRACTED_FROM, RDF_TYPE, ENHANCER_TEXTANNOTATION);
try {
selector = Utils.parseSelector(path);
} catch (ParseException e) {
throw new IllegalStateException("Unable to parse the ld-path selector '" + path + "'used to select all TextAnnotations of a contentItem!", e);
}
addFunction(CONFIG, new PathFunction<RDFTerm>("textAnnotation", selector));
//EntityAnnotations
path = String.format("^%s[%s is %s]", ENHANCER_EXTRACTED_FROM, RDF_TYPE, ENHANCER_ENTITYANNOTATION);
try {
selector = Utils.parseSelector(path);
} catch (ParseException e) {
throw new IllegalStateException("Unable to parse the ld-path selector '" + path + "'used to select all EntityAnnotations of a contentItem!", e);
}
addFunction(CONFIG, new PathFunction<RDFTerm>("entityAnnotation", selector));
//TopicAnnotations
path = String.format("^%s[%s is %s]", ENHANCER_EXTRACTED_FROM, RDF_TYPE, ENHANCER_TOPICANNOTATION);
try {
selector = Utils.parseSelector(path);
} catch (ParseException e) {
throw new IllegalStateException("Unable to parse the ld-path selector '" + path + "'used to select all TopicAnnotations of a contentItem!", e);
}
addFunction(CONFIG, new PathFunction<RDFTerm>("topicAnnotation", selector));
//Enhancements
path = String.format("^%s[%s is %s]", ENHANCER_EXTRACTED_FROM, RDF_TYPE, ENHANCER_ENHANCEMENT);
try {
selector = Utils.parseSelector(path);
} catch (ParseException e) {
throw new IllegalStateException("Unable to parse the ld-path selector '" + path + "'used to select all Enhancements of a contentItem!", e);
}
addFunction(CONFIG, new PathFunction<RDFTerm>("enhancement", selector));
//Suggested EntityAnnotations for Text/TopicAnnotations
//(1) to select the suggestions
NodeSelector<RDFTerm> linkedEntityAnnotations;
path = String.format("^%s[%s is %s]", DC_RELATION, RDF_TYPE, ENHANCER_ENTITYANNOTATION, ENHANCER_CONFIDENCE);
try {
linkedEntityAnnotations = Utils.parseSelector(path);
} catch (ParseException e) {
throw new IllegalStateException("Unable to parse the ld-path selector '" + path + "'used to select all entity suggestions for an Enhancement!", e);
}
//(2) to select the confidence value of Enhancements
NodeSelector<RDFTerm> confidenceSelector;
path = ENHANCER_CONFIDENCE.toString();
try {
confidenceSelector = Utils.parseSelector(path);
} catch (ParseException e) {
throw new IllegalStateException("Unable to parse the ld-path selector '" + path + "'used to select the confidence of suggestions!", e);
}
//The resultSelector is NULL because this directly returns the EntityAnnotations
addFunction(CONFIG, new SuggestionFunction("suggestion", linkedEntityAnnotations, confidenceSelector, null));
//Suggested Entities for Text/TopicAnnotations
//The suggestion and confidence selectors can be the same as above,
//but we need an additional result selector
NodeSelector<RDFTerm> entityReferenceSelector;
path = ENHANCER_ENTITY_REFERENCE.toString();
try {
entityReferenceSelector = Utils.parseSelector(path);
} catch (ParseException e) {
throw new IllegalStateException("Unable to parse the ld-path selector '" + path + "'used to select the entity referenced by a EntityAnnotation!", e);
}
addFunction(CONFIG, new SuggestionFunction("suggestedEntity", linkedEntityAnnotations, confidenceSelector, entityReferenceSelector));
}
return CONFIG;
}
Aggregations