Search in sources :

Example 16 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class ManagedEntity method canWrap.

/**
     * Checks if the parsed Entity can be wrapped as a locally managed entity.
     * This checks currently of a {@link ManagedEntityState} is defined by the
     * metadata.
     * @param entity the entity to check
     * @return the state
     */
public static boolean canWrap(Entity entity) {
    //check the metadata for
    //if the entity is managed locally
    //if the entity has an state
    Reference stateUri = entity.getMetadata().getFirstReference(STATE);
    if (stateUri == null || !ManagedEntityState.isState(stateUri.getReference())) {
        return false;
    }
    //check the about
    String entityId = ModelUtils.getAboutRepresentation(entity.getMetadata());
    if (entityId == null || !entityId.equals(entity.getRepresentation().getId())) {
        return false;
    }
    return true;
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference)

Example 17 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class ManagedEntity method init.

/**
     * Sets the parsed default state to the metadata if no other one is already
     * present and that wraps the entity as locally managed entity.
     * @param entity the entity
     * @param defaultState the default state used if no one is yet defined for
     * this entity
     * @return the wrapped entity
     */
public static ManagedEntity init(Entity entity, ManagedEntityState defaultState) {
    Reference stateUri = entity.getMetadata().getFirstReference(STATE);
    if (stateUri == null || !ManagedEntityState.isState(stateUri.getReference())) {
        entity.getMetadata().setReference(STATE, defaultState.getUri());
    }
    String entityId = ModelUtils.getAboutRepresentation(entity.getMetadata());
    if (entityId == null) {
        entity.getMetadata().setReference(RdfResourceEnum.aboutRepresentation.getUri(), entity.getRepresentation().getId());
    } else if (!entityId.equals(entity.getRepresentation().getId())) {
        //the metadata are about a different Entity ->
        throw new IllegalArgumentException(String.format("The Metadata of the parsed Entity are not about the Entity (" + "entity: %s | metadataId: %s | metadataAbout: %s)", entity.getRepresentation().getId(), entity.getMetadata().getId(), entityId));
    }
    //else the ID value is OK
    return new ManagedEntity(entity, false);
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference)

Example 18 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class GeonamesConstants method getReference.

/**
     * Caches references for parsed strings. Intended to be used for
     * Entiries of the geonames ontology.
     * @param refString the string reference
     * @return the {@link Reference} for the parsed String
     */
public static Reference getReference(String refString) {
    Reference ref = indexDocRefs.get(refString);
    if (ref == null) {
        ref = valueFactory.createReference(refString);
        indexDocRefs.put(refString, ref);
    }
    return ref;
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference)

Example 19 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class GeonamesEntityScoreProvider method process.

@Override
public Float process(Representation entity) throws UnsupportedOperationException {
    Reference ref = entity.getFirstReference(GeonamesPropertyEnum.gn_featureClass.toString());
    String fclass = ref == null ? null : ref.getReference();
    if (FCLASS_A.equals(fclass)) {
        ref = entity.getFirstReference(GeonamesPropertyEnum.gn_featureCode.toString());
        String fcode = ref == null ? null : ref.getReference();
        if (fcode == null) {
            return DEFAULT_SCORE;
        } else {
            fcode = fcode.substring(GEONAMES_ONTOLOGY_NS.length() + 2);
            if (fcode.length() > 2 && fcode.startsWith("PC")) {
                return Float.valueOf(1.0f);
            } else if (fcode.length() > 3 && fcode.charAt(3) == '1') {
                return Float.valueOf(0.5f);
            } else if (fcode.length() > 3 && fcode.charAt(3) == '2') {
                return Float.valueOf(0.25f);
            } else if (fcode.length() > 3 && fcode.charAt(3) == '3') {
                return Float.valueOf(0.125f);
            } else if (fcode.length() > 3 && (fcode.charAt(3) == '4' || fcode.charAt(3) == 'D')) {
                return Float.valueOf(0.062f);
            } else if (fcode.length() > 3 && fcode.charAt(3) == '5') {
                return Float.valueOf(0.031f);
            } else {
                return Float.valueOf(0.062f);
            }
        }
    } else if (FCLASS_P.equals(fclass)) {
        Long population = entity.getFirst(GeonamesPropertyEnum.gn_population.toString(), Long.class);
        if (population == null) {
            //use 1 to avoid creating a new instance
            population = Long.valueOf(1);
        }
        //normalise the population
        double p = Math.max(Math.min(MAX_POPULATION, population.longValue()), MIN_POPULATION);
        //population factor
        double fact = Math.log1p(p / POPULATION_SCALE);
        //Normalised based on the maximum popuoation
        Float score = Float.valueOf((float) (fact / FACT));
        return score;
    } else {
        return DEFAULT_SCORE;
    }
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference)

Example 20 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class RdfIndexingSourceTest method testReference.

private void testReference(Representation rep) {
    for (Iterator<String> fields = rep.getFieldNames(); fields.hasNext(); ) {
        String field = fields.next();
        Iterator<Reference> values = rep.getReferences(field);
        //            assertTrue(values.hasNext());
        while (values.hasNext()) {
            Reference ref = values.next();
            assertNotNull(ref);
        }
    }
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference)

Aggregations

Reference (org.apache.stanbol.entityhub.servicesapi.model.Reference)30 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)12 Text (org.apache.stanbol.entityhub.servicesapi.model.Text)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)7 ValueFactory (org.apache.stanbol.entityhub.servicesapi.model.ValueFactory)7 IRI (org.apache.clerezza.commons.rdf.IRI)5 URI (java.net.URI)4 URL (java.net.URL)3 URI (org.openrdf.model.URI)3 HashSet (java.util.HashSet)2 Language (org.apache.clerezza.commons.rdf.Language)2 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)2 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)2 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)2 Yard (org.apache.stanbol.entityhub.servicesapi.yard.Yard)2 YardTest (org.apache.stanbol.entityhub.test.yard.YardTest)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Value (org.openrdf.model.Value)2 Date (java.util.Date)1