Search in sources :

Example 6 with RdfEntityFactory

use of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory in project stanbol by apache.

the class TestEntityLinkingEnhancementEngine method getTextAnnotation.

public static void getTextAnnotation(ContentItem ci, String name, String context, IRI type) {
    String content;
    try {
        content = IOUtils.toString(ci.getStream(), "UTF-8");
    } catch (IOException e) {
        //should never happen anyway!
        content = "";
    }
    RdfEntityFactory factory = RdfEntityFactory.createInstance(ci.getMetadata());
    TextAnnotation textAnnotation = factory.getProxy(new IRI("urn:iks-project:enhancer:test:text-annotation:" + randomUUID()), TextAnnotation.class);
    textAnnotation.setCreator(new IRI("urn:iks-project:enhancer:test:dummyEngine"));
    textAnnotation.setCreated(new Date());
    textAnnotation.setSelectedText(name);
    textAnnotation.setSelectionContext(context);
    textAnnotation.getDcType().add(type);
    Integer start = content.indexOf(name);
    if (start < 0) {
        //if not found in the content
        //set some random numbers for start/end
        start = (int) (Math.random() * 100);
    }
    textAnnotation.setStart(start);
    textAnnotation.setEnd(start + name.length());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RdfEntityFactory(org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory) IOException(java.io.IOException) TextAnnotation(org.apache.stanbol.enhancer.rdfentities.fise.TextAnnotation) Date(java.util.Date)

Example 7 with RdfEntityFactory

use of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory in project stanbol by apache.

the class RdfEntityFactoryTest method testPrimitiveDataTypes.

@Test
public void testPrimitiveDataTypes() throws Exception {
    Graph graph = new SimpleGraph();
    RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
    String testUri = "urn:RdfEntityFactoryTest:TestEntity";
    IRI node = new IRI(testUri);
    TestRdfEntity testEntity = factory.getProxy(node, TestRdfEntity.class);
    testEntity.setBoolean(true);
    assertTrue(testEntity.getBoolean());
    testEntity.setInteger(10);
    assertEquals(new Integer(10), testEntity.getInteger());
    testEntity.setLong(20l);
    assertEquals(new Long(20), testEntity.getLong());
    //TODO: Not supported by org.apache.clerezza.rdf.core.impl.SimpleLiteralFactory!
    //testEntity.setFloat(0.1f);
    //assertTrue(new Float(0.1f).equals(testEntity.getFloat()));
    testEntity.setDouble(0.2);
    assertEquals(new Double(0.2), testEntity.getDouble());
    testEntity.setString("Test!");
    assertEquals("Test!", testEntity.getString());
    Date currentDate = new Date();
    testEntity.setDate(currentDate);
    assertEquals(currentDate, testEntity.getDate());
    testEntity.setIntegers(Arrays.asList(new Integer(1), new Integer(2), new Integer(3)));
    Collection<Integer> integers = testEntity.getIntegers();
    assertTrue(integers.contains(new Integer(1)));
    assertTrue(integers.contains(new Integer(2)));
    assertTrue(integers.contains(new Integer(3)));
    //test Remove
    integers.remove(new Integer(2));
    assertTrue(integers.contains(new Integer(1)));
    assertTrue(!integers.contains(new Integer(2)));
    assertTrue(integers.contains(new Integer(3)));
    //get an new Collection and repeat the test
    integers = testEntity.getIntegers();
    assertTrue(integers.contains(new Integer(1)));
    assertTrue(!integers.contains(new Integer(2)));
    assertTrue(integers.contains(new Integer(3)));
    //test Add
    integers.add(new Integer(-1));
    assertTrue(integers.contains(new Integer(-1)));
    assertTrue(integers.contains(new Integer(1)));
    assertTrue(integers.contains(new Integer(3)));
    //again get a new collection
    Collection<Integer> integers2 = testEntity.getIntegers();
    assertTrue(integers2.contains(new Integer(-1)));
    assertTrue(integers2.contains(new Integer(1)));
    assertTrue(integers2.contains(new Integer(3)));
    //remove/add an value in integers and test in integers2
    integers.remove(new Integer(3));
    integers.add(new Integer(0));
    assertTrue(integers2.contains(new Integer(-1)));
    assertTrue(integers2.contains(new Integer(0)));
    assertTrue(integers2.contains(new Integer(1)));
    assertTrue(!integers2.contains(new Integer(2)));
    assertTrue(!integers2.contains(new Integer(3)));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) RdfEntityFactory(org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Date(java.util.Date) Test(org.junit.Test)

Example 8 with RdfEntityFactory

use of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory in project stanbol by apache.

the class RdfEntityFactoryTest method testRdfEntity.

@Test
public void testRdfEntity() throws Exception {
    Graph graph = new SimpleGraph();
    RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
    String testUri = "urn:RdfEntityFactoryTest:TestEntity";
    IRI node = new IRI(testUri);
    RdfEntity rdfEntity = factory.getProxy(node, RdfEntity.class);
    //TODO: Test type statement
    //TODO: test getID Method
    assertEquals(rdfEntity.getId(), node);
    //TODO: Test equals
    RdfEntity rdfEntity2 = factory.getProxy(node, RdfEntity.class);
    assertEquals(rdfEntity, rdfEntity2);
    //TODO: Test hashCode
    assertEquals(rdfEntity.hashCode(), rdfEntity2.hashCode());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) RdfEntityFactory(org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) RdfEntity(org.apache.stanbol.enhancer.rdfentities.RdfEntity) Test(org.junit.Test)

Aggregations

IRI (org.apache.clerezza.commons.rdf.IRI)8 RdfEntityFactory (org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory)8 Test (org.junit.Test)6 Graph (org.apache.clerezza.commons.rdf.Graph)5 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)5 Date (java.util.Date)4 TextAnnotation (org.apache.stanbol.enhancer.rdfentities.fise.TextAnnotation)3 IOException (java.io.IOException)2 Rdf (org.apache.stanbol.enhancer.rdfentities.Rdf)2 RdfEntity (org.apache.stanbol.enhancer.rdfentities.RdfEntity)2 URI (java.net.URI)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 InMemoryContentItem (org.apache.stanbol.enhancer.contentitem.inmemory.InMemoryContentItem)1 EntityAnnotation (org.apache.stanbol.enhancer.rdfentities.fise.EntityAnnotation)1 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)1