Search in sources :

Example 16 with ValueFactory

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);
}
Also used : SesameYard(org.apache.stanbol.entityhub.yard.sesame.SesameYard) Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) RdfRepresentation(org.apache.stanbol.entityhub.model.sesame.RdfRepresentation) ValueFactory(org.apache.stanbol.entityhub.servicesapi.model.ValueFactory) Test(org.junit.Test) YardTest(org.apache.stanbol.entityhub.test.yard.YardTest)

Example 17 with ValueFactory

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;
    }
}
Also used : ValueFactory(org.apache.stanbol.entityhub.servicesapi.model.ValueFactory) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) StringReader(java.io.StringReader) LDPathParseException(org.apache.marmotta.ldpath.exception.LDPathParseException) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) DereferenceConfigurationException(org.apache.stanbol.enhancer.engines.dereference.DereferenceConfigurationException) HashSet(java.util.HashSet)

Aggregations

ValueFactory (org.apache.stanbol.entityhub.servicesapi.model.ValueFactory)17 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)14 Reference (org.apache.stanbol.entityhub.servicesapi.model.Reference)7 Test (org.junit.Test)7 URI (java.net.URI)4 HashSet (java.util.HashSet)4 LDPathParseException (org.apache.marmotta.ldpath.exception.LDPathParseException)4 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)4 Text (org.apache.stanbol.entityhub.servicesapi.model.Text)4 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)3 LDPathSelect (org.apache.stanbol.entityhub.ldpath.query.LDPathSelect)3 RdfValueFactory (org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)3 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)3 Yard (org.apache.stanbol.entityhub.servicesapi.yard.Yard)3 URL (java.net.URL)2 ManagedSiteException (org.apache.stanbol.entityhub.servicesapi.site.ManagedSiteException)2 AdaptingIterator (org.apache.stanbol.entityhub.servicesapi.util.AdaptingIterator)2 YardTest (org.apache.stanbol.entityhub.test.yard.YardTest)2 StringReader (java.io.StringReader)1