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());
}
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)));
}
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());
}
Aggregations