Package org.apache.stanbol.entityhub.servicesapi.model

Examples of org.apache.stanbol.entityhub.servicesapi.model.ValueFactory


     * @return the mapped representation
     */
    private Representation applyCacheMappings(Yard yard, Representation representation) {
        long start = System.currentTimeMillis();
        Representation mapped = null;
        ValueFactory valueFactory = getValueFactory();
        if (baseMapper != null) {
            mapped = yard.getValueFactory().createRepresentation(representation.getId());
            baseMapper.applyMappings(representation, mapped,valueFactory);
        }
        if (additionalMapper != null) {
View Full Code Here


            log.warn("Unable to import Entity {} because the ReferencedSite {} is currently not active -> return null",
                remoteEntity.getId(),remoteEntity.getSite());
            return null;
        }
        Yard entityhubYard = lookupYard();
        ValueFactory valueFactory = entityhubYard.getValueFactory();
        //Create the locally managed Entity
        Representation localRep = entityhubYard.create(constructResourceId(DEFAULT_MANAGED_ENTITY_PREFIX));
        Entity localEntity = loadEntity(entityhubYard, localRep);
        importEntity(remoteEntity, site, localEntity, valueFactory);
View Full Code Here

    @Override
    public Program<Object> getParsedProgramByName(String programName) {
        SiteManagerBackend backend = new SiteManagerBackend(referencedSiteManager);
        String ldPathProgram = getProgramByName(programName);
        ValueFactory vf = InMemoryValueFactory.getInstance();
        EntityhubLDPath ldPath = new EntityhubLDPath(backend, vf);
        Program<Object> program = null;
        try {
            program = ldPath.parseProgram(LDPathUtils.constructReader(ldPathProgram));
        } catch (LDPathParseException e) {
View Full Code Here

    @Override
    public Map<String,Collection<?>> executeProgram(String programName, Set<String> contexts, ContentItem ci) throws LDPathException {
        Map<String,Collection<?>> results = new HashMap<String,Collection<?>>();
        SiteManagerBackend backend = new SiteManagerBackend(referencedSiteManager);
        String ldPathProgram = getProgramByName(programName);
        ValueFactory vf = InMemoryValueFactory.getInstance();
        EntityhubLDPath ldPath = new EntityhubLDPath(backend, vf);
        Program<Object> program = null;
        try {
            program = ldPath.parseProgram(LDPathUtils.constructReader(ldPathProgram));
        } catch (LDPathParseException e) {
            logger.error("Should never happen!!!!!", e);
            return Collections.emptyMap();
        }

        Representation representation;
        for (String context : contexts) {
            representation = ldPath.execute(vf.createReference(context), program);
            Iterator<String> fieldNames = representation.getFieldNames();
            while (fieldNames.hasNext()) {
                String fieldName = fieldNames.next();
                Iterator<Object> valueIterator = representation.get(fieldName);
                if (!valueIterator.hasNext()) continue;
View Full Code Here

     */
    @Override
    public void store(final Iterable<Representation> representations) throws ManagedSiteException {
        try {
            Yard yard = getYard();
            final ValueFactory vf = yard.getValueFactory();
            yard.store(new Iterable<Representation>() {               
                @Override
                public Iterator<Representation> iterator() {
                    return new Iterator<Representation>() {
                        Iterator<Representation> it = representations.iterator();
View Full Code Here

     * @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(RDF.type.getUnicodeString()).hasNext());
        //now add the statement and see if an IllegalStateException is thrown
        /*
 
View Full Code Here

     * @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
        /*
 
View Full Code Here

     * @param headers the http headers of the request
     * @return the response
     */
    private Response executeLDPathQuery(Entityhub entityhub,FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
        QueryResultList<Representation> result;
        ValueFactory vf = new RdfValueFactory(new IndexedMGraph());
        EntityhubBackend backend = new EntityhubBackend(entityhub);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        //copy the selected fields, because we might need to delete some during
        //the preparation phase
        Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
View Full Code Here

     * @param headers the http headers of the request
     * @return the response
     */
    private Response executeLDPathQuery(FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
        QueryResultList<Representation> result;
        ValueFactory vf = new RdfValueFactory(new IndexedMGraph());
        SiteBackend backend = new SiteBackend(site,vf);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        //copy the selected fields, because we might need to delete some during
        //the preparation phase
        Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
View Full Code Here

    }

    @Test
    public void testFieldRemoval() throws URISyntaxException {
        String field = "urn:the.field:used.for.this.Test";
        ValueFactory vf = getValueFactory();
        Representation rep = createRepresentation(null);
        // Test removal for References
        String strRef = "urn:testValue";
        rep.addReference(field, strRef);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.removeReference(field, strRef);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        Reference ref = vf.createReference("urn:testValue2");
        rep.add(field, ref);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.remove(field, ref);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        // test removal for texts (with and without language)
        String strText = "test text";
        String strTextLang = "en";
        rep.addNaturalText(field, strText, strTextLang);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.removeNaturalText(field, strText, strTextLang);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        String strTextNoLang = "test text without lang";
        rep.addNaturalText(field, strTextNoLang);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.removeNaturalText(field, strTextNoLang);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        // there is also the possibility to explicitly parse null as language
        // could internally case differences however externally this is the same
        rep.addNaturalText(field, strTextNoLang, (String) null);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.removeNaturalText(field, strTextNoLang, (String) null);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        Text text = vf.createText("Das ist ein Text zum testen des Text Objektes", "de");
        rep.add(field, text);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.remove(field, text);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.model.ValueFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.