Search in sources :

Example 11 with Reference

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

the class RepresentationTest method testMultipleAddAndRemove.

@Test
public void testMultipleAddAndRemove() throws MalformedURLException, URISyntaxException {
    String field = "urn:the.field:used.for.this.Test";
    ValueFactory vf = getValueFactory();
    Representation rep = createRepresentation(null);
    Reference ref = vf.createReference("http://www.test.org/test");
    Text text = vf.createText("test", "en");
    Integer i = 42;
    Double d = Math.PI;
    URI uri = new URI("http://www.test.org/uriTest");
    URL url = new URL("http://www.test.org/urlTest");
    String[] textAsArray = new String[] { "Test text as Array", "en" };
    Collection<Object> values = Arrays.asList(ref, text, i, d);
    Collection<Object> convertedValues = Arrays.asList((Object) url, uri, textAsArray);
    Collection<Object> allValues = Arrays.asList(ref, text, i, d, uri, url, textAsArray);
    // test adding of collections
    rep.add(field, values);
    assertTrue(asCollection(rep.get(field)).size() == 4);
    rep.remove(field, values);
    assertFalse(rep.get(field).hasNext());
    // test adding of Iterators
    rep.add(field, values.iterator());
    assertTrue(asCollection(rep.get(field)).size() == 4);
    rep.remove(field, values.iterator());
    assertFalse(rep.get(field).hasNext());
    // test adding of Enumerations
    Vector<Object> v = new Vector<Object>(values);
    rep.add(field, v.elements());
    assertTrue(asCollection(rep.get(field)).size() == 4);
    rep.remove(field, v.elements());
    assertFalse(rep.get(field).hasNext());
    // test adding and removing elements that need to be converted
    // only for collections this time -> want to test only converting is
    // applied for both add and remove
    rep.add(field, convertedValues);
    assertTrue(asCollection(rep.get(field)).size() == 3);
    rep.remove(field, convertedValues);
    assertFalse(rep.get(field).hasNext());
    // a final test to ensure, that remove does not only delete all values
    rep.add(field, allValues);
    assertTrue(asCollection(rep.get(field)).size() == 7);
    rep.remove(field, convertedValues);
    assertTrue(asCollection(rep.get(field)).size() == 4);
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Text(org.apache.stanbol.entityhub.servicesapi.model.Text) ValueFactory(org.apache.stanbol.entityhub.servicesapi.model.ValueFactory) URI(java.net.URI) URL(java.net.URL) Vector(java.util.Vector) Test(org.junit.Test)

Example 12 with Reference

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

the class ValueFactoryTest method testStringReference.

@Test
public void testStringReference() {
    Object refObject = "urn:test.1";
    Reference ref = testRef(refObject);
    assertEquals(ref.getReference(), refObject);
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Test(org.junit.Test)

Example 13 with Reference

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

the class ValueFactoryTest method testIRIerence.

@Test
public void testIRIerence() throws URISyntaxException {
    URI refObject = new URI("http://www.test.org/uriTest");
    Reference ref = testRef(refObject);
    assertEquals(ref.getReference(), refObject.toString());
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) URI(java.net.URI) Test(org.junit.Test)

Example 14 with Reference

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

the class ValueFactoryTest method testURLReference.

@Test
public void testURLReference() throws MalformedURLException {
    URL refObject = new URL("http://www.test.org/urlTest");
    Reference ref = testRef(refObject);
    assertEquals(ref.getReference(), refObject.toString());
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) URL(java.net.URL) Test(org.junit.Test)

Example 15 with Reference

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

the class EntityLinker method getLinkedEntityTypes.

/**
     * Retrieves all {@link EntitySearcher#getTypeField()} values of the parsed
     * {@link Suggestion}s and than lookup the {@link NamespaceEnum#dcTerms dc}:type
     * values for the {@link LinkedEntity#getTypes()} by using the configured
     * {@link EntityLinkerConfig#getTypeMappings() types mappings} (and if
     * no mapping is found the {@link EntityLinkerConfig#getDefaultDcType() 
     * default} type.
     * @param conceptTypes The list of suggestions
     * @return the types values for the {@link LinkedEntity}
     */
private Set<IRI> getLinkedEntityTypes(Collection<Suggestion> suggestions) {
    Collection<String> conceptTypes = new HashSet<String>();
    for (Suggestion suggestion : suggestions) {
        for (Iterator<Reference> types = suggestion.getRepresentation().getReferences(config.getTypeField()); types.hasNext(); conceptTypes.add(types.next().getReference())) ;
    }
    Map<String, IRI> typeMappings = config.getTypeMappings();
    Set<IRI> dcTypes = new HashSet<IRI>();
    for (String conceptType : conceptTypes) {
        IRI dcType = typeMappings.get(conceptType);
        if (dcType != null) {
            dcTypes.add(dcType);
        }
    }
    if (dcTypes.isEmpty() && config.getDefaultDcType() != null) {
        dcTypes.add(config.getDefaultDcType());
    }
    return dcTypes;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) HashSet(java.util.HashSet)

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