use of org.apache.stanbol.entityhub.servicesapi.model.ValueFactory in project stanbol by apache.
the class SesameYardTest method testRemovalOfTypeRepresentationStatement.
/**
* The Clerezza Yard uses the Statement<br>
* <code>representationId -> rdf:type -> Representation</code><br>
* to identify that an UriRef in the RDF graph (MGraph) represents a
* Representation. This Triple is added when a Representation is stored and
* removed if retrieved from the Yard.<p>
* This tests if this functions as expected
* @throws YardException
*/
@Test
public void testRemovalOfTypeRepresentationStatement() throws YardException {
Yard yard = getYard();
ValueFactory vf = yard.getValueFactory();
Reference representationType = vf.createReference(RdfResourceEnum.Representation.getUri());
Representation test = create();
//the rdf:type Representation MUST NOT be within the Representation
Assert.assertFalse(test.get(NamespaceEnum.rdf + "type").hasNext());
//now add the statement and see if an IllegalStateException is thrown
/*
* The triple within this Statement is internally used to "mark" the
* URI of the Representation as
*/
test.add(NamespaceEnum.rdf + "type", representationType);
}
use of org.apache.stanbol.entityhub.servicesapi.model.ValueFactory in project stanbol by apache.
the class EntityhubDereferenceContext method initLdPath.
protected void initLdPath(String program) throws DereferenceConfigurationException {
TrackingDereferencerBase<?> dereferencer = getEntityhubDereferencer();
ValueFactory valueFactory = dereferencer.getValueFactory();
Program<Object> ldpathProgram;
if (!StringUtils.isBlank(program)) {
@SuppressWarnings("rawtypes") RDFBackend<Object> parseBackend = new ParseBackend<Object>(valueFactory);
EntityhubLDPath parseLdPath = new EntityhubLDPath(parseBackend, valueFactory);
try {
ldpathProgram = parseLdPath.parseProgram(new StringReader(program));
} catch (LDPathParseException e) {
log.error("Unable to parse Context LDPath pogram: \n {}", program);
throw new DereferenceConfigurationException("Unable to parse context LDPath program !", e, dereferencer.getClass(), DEREFERENCE_ENTITIES_LDPATH);
}
//finally validate if all mappings of the program do use a URI as key
//also store used fieldNames as we need them later
Set<String> contextFields = new HashSet<String>();
for (org.apache.marmotta.ldpath.model.fields.FieldMapping<?, Object> mapping : ldpathProgram.getFields()) {
try {
new URI(mapping.getFieldName());
contextFields.add(mapping.getFieldName());
} catch (URISyntaxException e) {
throw new DereferenceConfigurationException("Parsed LDPath MUST use valid URIs as field names (invalid field name: '" + mapping.getFieldName() + "' | selector: '" + mapping.getSelector().getPathExpression(parseBackend) + "')!", dereferencer.getClass(), DereferenceConstants.DEREFERENCE_ENTITIES_LDPATH);
}
}
//append the mappings configured for the engine
if (dereferencer.getLdPathProgram() != null) {
for (org.apache.marmotta.ldpath.model.fields.FieldMapping<?, Object> mapping : dereferencer.getLdPathProgram().getFields()) {
if (!contextFields.contains(mapping.getFieldName())) {
ldpathProgram.addMapping(mapping);
}
//else ignore mappings for fields specified in the context
}
}
} else {
//no context specific - use the one of the config
ldpathProgram = dereferencer.getLdPathProgram();
}
if (ldpathProgram != null && !ldpathProgram.getFields().isEmpty()) {
this.ldpathProgram = ldpathProgram;
} else {
this.ldpathProgram = null;
}
}
Aggregations