use of org.apache.marmotta.ldpath.LDPath in project stanbol by apache.
the class LdpathSourceProcessor method setConfiguration.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void setConfiguration(Map<String, Object> config) {
indexingConfig = (IndexingConfig) config.get(IndexingConfig.KEY_INDEXING_CONFIG);
Object indexingSource;
//we need to check for both EntityDataProvider and EntityDataIterator
indexingSource = indexingConfig.getEntityDataProvider();
if (indexingSource == null) {
indexingSource = indexingConfig.getDataIterable();
}
if (indexingSource == null) {
throw new IllegalStateException("Indexing Configuration does not contain" + "neither an EntityDataProvider nor an EntityIdIterator!");
}
if (indexingSource instanceof RDFBackend<?>) {
//NOTE we use the EntityhubConfiguration to have the same pre-registered
// namespaces as the other components.
this.backend = (RDFBackend) indexingSource;
this.configuration = new EntityhubConfiguration(vf);
this.transformer = configuration.getTransformers();
this.ldPath = new LDPath(backend, configuration);
} else {
throw new IllegalArgumentException("The configured IndexingSource '" + indexingSource.getClass().getSimpleName() + "' does not support " + "LDPath (does not implement RDFBackend)! This Processor " + "can only be used with IndexingSources that support LDPath!");
}
Object value = config.get(PARAMETER_LD_PATH);
final File ldpathFile;
if (value != null && !value.toString().isEmpty()) {
ldpathFile = indexingConfig.getConfigFile(value.toString());
if (ldpathFile == null || !ldpathFile.exists()) {
throw new IllegalArgumentException("Configured '" + PARAMETER_LD_PATH + "' file was not found!");
}
if (!ldpathFile.isFile()) {
throw new IllegalArgumentException("Configured '" + PARAMETER_LD_PATH + "' file exists but is not a File!");
}
} else {
throw new IllegalArgumentException("Missing required configuration '" + PARAMETER_LD_PATH + "' - the file containing the LDPath program used by this " + LdpathProcessor.class.getSimpleName() + "!");
}
//The backend needs not to be initialised to parse a program as
//parsing only requires the "value converter" methods that need also to
//work without initialising
//if this is a Problem one can also move parsing to the init method
parseLdPathProgram(ldpathFile);
value = config.get(PARAMETER_APPEND);
if (value instanceof Boolean) {
this.appendMode = ((Boolean) value).booleanValue();
} else if (value != null && !value.toString().isEmpty()) {
this.appendMode = Boolean.parseBoolean(value.toString());
} else {
this.appendMode = DEFAULT_APPEND_MODE;
}
}
use of org.apache.marmotta.ldpath.LDPath in project stanbol by apache.
the class BackendTest method testSingleRepresentationBackend.
@Test
public void testSingleRepresentationBackend() throws Exception {
Representation paris = yard.getRepresentation("http://dbpedia.org/resource/Paris");
assertNotNull(paris);
SingleRepresentationBackend backend = new SingleRepresentationBackend();
backend.setRepresentation(paris);
LDPath<Object> ldPath = new LDPath<Object>(backend);
StringBuilder sb = new StringBuilder();
sb.append("myTest = .[rdf:type is <http://dbpedia.org/ontology/Place>]/rdfs:label;");
Program<Object> program = ldPath.parseProgram(new StringReader(sb.toString()));
Map<String, Collection<?>> result = program.execute(backend, yard.getValueFactory().createReference(paris.getId()));
Assert.assertNotNull(result);
Assert.assertTrue(result.containsKey("myTest"));
Collection<?> values = result.get("myTest");
Assert.assertNotNull(values);
Assert.assertFalse(values.isEmpty());
sb = new StringBuilder();
sb.append("myTest = .[rdf:type is <http://dbpedia.org/ontology/Place2>]/rdfs:label;");
program = ldPath.parseProgram(new StringReader(sb.toString()));
result = program.execute(backend, yard.getValueFactory().createReference(paris.getId()));
Assert.assertNotNull(result);
values = result.get("myTest");
Assert.assertTrue(values == null || values.isEmpty());
}
use of org.apache.marmotta.ldpath.LDPath 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));
}
Aggregations