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

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


        // test
        String id = "urn:yard.test.tesrRemoveRepresentation:representation.id";
        String field = "urn:the.field:used.for.this.Test";
        String testValue = "This is a test";
        Yard yard = getYard();
        Representation test = yard.getValueFactory().createRepresentation(id);
        test.add(field, testValue);
        yard.store(test); // store the representation
        assertTrue(yard.isRepresentation(test.getId())); // test if stored
        test = null; // free the initial
        // create the instance form the store to test (2)
        test = yard.getRepresentation(id);
        assertEquals(id, test.getId()); // only to be sure ...
        yard.remove(test.getId()); // test (1) - the remove
        assertFalse(yard.isRepresentation(test.getId()));// test if removed
        // test if the test object is not destroyed by removing the representation
        // it represents form the store (2)
        assertEquals(testValue, test.getFirst(field));
    }
View Full Code Here


        String field = "urn:the.field:used.for.this.Test";
        String testValue = "This is a test";
        Yard yard = getYard();
        // use both ways to add the two Representations (should make no differences,
        // but one never can know ...
        Representation test1 = yard.create(id); // create and add
        Representation test2 = yard.getValueFactory().createRepresentation(id2); // create
        test2.add(field, testValue); // add value
        yard.store(test2);// store
        assertTrue(yard.isRepresentation(test1.getId())); // test if stored
        assertTrue(yard.isRepresentation(test2.getId()));
        yard.remove(Arrays.asList(test1.getId(), test2.getId())); // remove
        assertFalse(yard.isRepresentation(test1.getId())); // test if removed
        assertFalse(yard.isRepresentation(test2.getId()));
    }
View Full Code Here

        String field = "urn:the.field:used.for.this.Test";
        String testValue = "This is a test";
        Yard yard = getYard();
        // use both ways to add the two Representations (should make no differences,
        // but one never can know ...
        Representation test1 = yard.create(id); // create and add
        test1.add(field, testValue); // add value
        yard.store(test1);// store
        Representation test2 = yard.getValueFactory().createRepresentation(id2); // create
        test2.add(field, testValue); // add value
        yard.store(test2);// store
        assertTrue(yard.isRepresentation(test1.getId())); // test if stored
        assertTrue(yard.isRepresentation(test2.getId()));
        yard.removeAll(); // remove
        assertFalse(yard.isRepresentation(test1.getId())); // test if removed
        assertFalse(yard.isRepresentation(test2.getId()));
        //test that Yard is still useable after removeAll
        yard.store(test1);// store
        assertTrue(yard.isRepresentation(test1.getId())); // test if stored
        yard.removeAll(); // remove
        assertFalse(yard.isRepresentation(test1.getId()));
View Full Code Here

        // NOTE: This test needs not to use the create(..) method, because we
        // remove the created representation form the store anyway as part of the
        // test
        String id = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.id";
        Yard yard = getYard();
        Representation test = yard.create(id); // create and add
        assertTrue(yard.isRepresentation(test.getId()));
        yard.remove(Arrays.asList(test.getId(), null));
        assertFalse(yard.isRepresentation(test.getId()));
    }
View Full Code Here

        // remove the created representation form the store anyway as part of the
        // test
        String id = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.stored";
        String id2 = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.notStored";
        Yard yard = getYard();
        Representation test = yard.create(id); // create and add
        assertTrue(yard.isRepresentation(test.getId()));
        yard.remove(Arrays.asList(test.getId(), id2));
        assertFalse(yard.isRepresentation(test.getId()));
        assertFalse(yard.isRepresentation(id2));
    }
View Full Code Here

        String field = "urn:the.field:used.for.this.Test";
        String testValue = "This is a test";
        Yard yard = getYard();
        // use the ValueFactory to create the representation to ensure that this
        // instance has nothing to do with the store
        Representation test = create(id, false);
        // now store the empty Representation
        yard.store(test);
        // now add a values
        test.add(field, testValue);
        // now get the representation from the yard
        Representation stored = yard.getRepresentation(id);
        // test if the stored version does not contain the value
        assertFalse(stored.get(field).hasNext());
        stored = null;
        // now store the updated version
        yard.store(test);
        // now check that the updated value is stored
        stored = yard.getRepresentation(id);
        assertEquals(testValue, stored.getFirst(field));

        // now we need to test if modifications of an Representation returned
        test = stored;
        stored = null;
        String testValue2 = "This is an ohter test value";
        test.add(field, testValue2);

        // now get the representation from the yard and check that it still has
        // only one value
        stored = yard.getRepresentation(id);
        Collection<Object> values = asCollection(stored.get(field));
        assertTrue(values.remove(testValue)); // test that it contains the value
        assertTrue(values.isEmpty()); // and that there is only this value
        values = null;
        // now update the stored version with the new state
        stored = null;
        stored = yard.update(test);
        values = asCollection(stored.get(field));
        assertTrue(values.remove(testValue)); // test that it contains the original
        assertTrue(values.remove(testValue2)); // test that it contains the 2nd value
        assertTrue(values.isEmpty()); // and that there are only these two values
        values = null;
    }
View Full Code Here

                LineTokenizer t = new LineTokenizer(line);
                //[0] geonames id
                String id = t.next();
                Integer geoNamesId = Integer.parseInt(id);
                //create a new Doc based on the first Element (geonamesID)
                Representation doc = valueFactory.createRepresentation(
                    new StringBuilder(GEONAMES_RESOURCE_NS).append(id).toString());
                //add the Integer id so that we do not need to parse it from the subject URI
                doc.add(GeonamesPropertyEnum.idx_id.toString(), geoNamesId);
                //add the geonames:Feature type
                doc.add(GeonamesPropertyEnum.rdf_type.toString(), getReference(GeonamesPropertyEnum.gn_Feature.toString()));
                //[1] UTF-8 name
                String utf8Label = t.next();
                //[2] ASKII Name as rdfs:label
                String askiiLabel = t.next();
                if(utf8Label == null){
                    utf8Label = askiiLabel; //use ASKII label as fallback for the utf8 version
                }
                doc.addNaturalText(GeonamesPropertyEnum.gn_name.toString(),utf8Label);
                //[3] Alternate Names
                t.next(); //alternate names are added later during processing
                //addAlternateNames(geoNamesId, doc);
                //[4] lat
                doc.add(GeonamesPropertyEnum.geo_lat.toString(),new BigDecimal(t.next()));
                //[5] lon
                doc.add(GeonamesPropertyEnum.geo_long.toString(),new BigDecimal(t.next()));
                //[6] featureClass
                String featureClass = new StringBuilder(GEONAMES_ONTOLOGY_NS).append(t.next()).toString();
                doc.add(GeonamesPropertyEnum.gn_featureClass.toString(),getReference(featureClass));
                //[7] featureCode (-> need to use <featureClass>.<featureCode>!!)
                doc.add(GeonamesPropertyEnum.gn_featureCode.toString(),getReference(
                    new StringBuilder(featureClass).append(t.next()).toString()));
                //countryCode
                //  -> geonames uses here the link to an HTML Page showing the Country
                //     We would like to use an Link to a SKOS:Concept representing the Country
                // ... But luckily here we need only to add the URI!
                Set<String> ccs = new HashSet<String>();
                //[8] countryCode
                String countryCode = t.next();
                if(countryCode != null){
                    countryCode = countryCode.trim(); //need to trim because some country codes use '  ' to indicate null!
                    if(countryCode.length() == 2){ //Yes there are some features that are in no country!
                        ccs.add(countryCode);
                    }
                }
                //[9] alternate countryCodes
                String altCc = t.next();
                if(altCc != null){
                    StringTokenizer altCcT = new StringTokenizer(altCc,",");
                    while(altCcT.hasMoreElements()){
                        countryCode = altCcT.nextToken();
                        if(countryCode.length() ==2){
                            ccs.add(countryCode);
                        }
                    }
                }
                if(!ccs.isEmpty()){
                    doc.add(GeonamesPropertyEnum.gn_countryCode.toString(),ccs);
                }
                //[10 TO 13] Admin codes
                //first read them -> we need to consume the tokens anyway
                String[] adminCodes = new String[] {
                    countryCode, //country
                    t.next(), //ADM1
                    t.next(), //ADM2
                    t.next(), //ADM3
                    t.next()};//ADM4
                //Workaround for Admin1 -> add leading '0' for single Value
                if(adminCodes[1] != null && adminCodes[1].length() < 2){
                    adminCodes[1] = '0'+adminCodes[1];
                }
                //now process the admin Codes (including the country at index 0)
                for(int i=0;i<adminCodes.length;i++){
                    if(adminCodes[i] != null && !adminCodes[i].equals("00")){ //00 is used to indicate not known
                        StringBuilder parentCode = new StringBuilder();
                        for(int j=0;j<i;j++){
                            parentCode.append(adminCodes[j]); //add all the previous
                            parentCode.append('.'); //add the seperator char
                        }
                        parentCode.append(adminCodes[i]);//add the current (last) Element
                        String property = i==0 ? GeonamesPropertyEnum.idx_CC.toString() :
                            new StringBuilder(GeonamesPropertyEnum.idx_ADM.toString()).append(i).toString();
                        doc.add(property, parentCode.toString());
                    }
                }

                //[14] population
                String populationString = t.next();
                if(populationString != null){
                    //NOTE: we need to used Long, because of Asia (3.800.000)
                    Long population = new Long(populationString);
                    if(population.intValue() > 0){
                        doc.add(GeonamesPropertyEnum.gn_population.toString(),population);
                    }
                }
               
                //[15 TO 16] elevation and gtopo30
                String altString = t.next();
                if(altString == null){
                    altString = t.next(); //if no elevation than use the gtopo30
                } else {
                    t.next(); //if there is already en elevation, than consume these entry
                }
                Integer alt = Integer.valueOf(altString);
                if(alt.intValue() > -9999){ //it looks like that -9999 is sometimes used as not known!
                    doc.add(GeonamesPropertyEnum.geo_alt.toString(),alt);
                }
               
                //[17] time zone
                t.next(); //not used
                //[18] mod-date
                String modDateString = t.next();
                if(modDateString != null){
                    try {
                        doc.add(GeonamesPropertyEnum.dc_date.toString(),TimeUtils.toDate(DataTypeEnum.DateTime, modDateString));
                    }catch (IllegalArgumentException e) {
                        log.warn(String.format("Unable to parse modificationDate for geonamesID %s from value %s",doc.getId(),modDateString));
                    }
                }
                //no creator as this is anyway provided by attribution
                //doc.add(GeonamesPropertyEnum.dc_creator.toString(),"http://www.geonames.org/");
                return doc;
View Full Code Here

        } 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;
                Set<Object> values = new HashSet<Object>();
                while (valueIterator.hasNext()) {
                    values.add(valueIterator.next());
                }
View Full Code Here

        return fieldQuery;
    }

    private Map<String,List<RelatedKeyword>> getRelatedKeywordsFromEntity(Entity entity) {
        Map<String,List<RelatedKeyword>> results = new HashMap<String,List<RelatedKeyword>>();
        Representation entityRep = entity.getRepresentation();
        for (Iterator<String> fields = entityRep.getFieldNames(); fields.hasNext();) {
            String field = fields.next();
            processProperties(organizationTypedProperties, entity.getRepresentation(), entity.getSite()
                                                                                       + "#Organization",
                field, results);
            processProperties(personTypedProperties, entity.getRepresentation(),
View Full Code Here

                sb.append(currentEntity.getBlankNodeId().getLabelString());
                uri = sb.toString();
            } else {
                uri = currentEntity.getURI();
            }
            Representation representation = vf.createRepresentation(uri);
            Iterator<Node> it = data.iterator();
            while(it.hasNext()){
                //data contains field,value pairs
                //because of that we call two times next for
                String field = it.next().getURI(); //the field
View Full Code Here

TOP

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

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.