return ciFactory.createContentItem(cs);
}
@Test
public void testEnhancementInterfaces() throws Exception {
ContentItem ci = createContentItem(SINGLE_SENTENCE_SOURCE);
UriRef ciUri = new UriRef(ci.getUri().getUnicodeString());
RdfEntityFactory factory = RdfEntityFactory.createInstance(ci.getMetadata());
long start = System.currentTimeMillis();
//create an Text Annotation representing an extracted Person
TextAnnotation personAnnotation = factory.getProxy(
createEnhancementURI(), TextAnnotation.class);
personAnnotation.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
personAnnotation.setCreated(new Date());
personAnnotation.setExtractedFrom(ciUri);
personAnnotation.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/text#Person"));
personAnnotation.setConfidence(0.8);
personAnnotation.setSelectedText("Patrick Marshall");
personAnnotation.setStart(SINGLE_SENTENCE.indexOf(personAnnotation.getSelectedText()));
personAnnotation.setEnd(personAnnotation.getStart()+personAnnotation.getSelectedText().length());
personAnnotation.setSelectionContext(SINGLE_SENTENCE);
//create an Text Annotation representing an extracted Location
TextAnnotation locationAnnotation = factory.getProxy(
createEnhancementURI(), TextAnnotation.class);
locationAnnotation.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
locationAnnotation.setCreated(new Date());
locationAnnotation.setExtractedFrom(ciUri);
locationAnnotation.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/text#Location"));
locationAnnotation.setConfidence(0.78);
locationAnnotation.setSelectedText("New Zealand");
locationAnnotation.setStart(SINGLE_SENTENCE.indexOf(locationAnnotation.getSelectedText()));
locationAnnotation.setEnd(locationAnnotation.getStart()+locationAnnotation.getSelectedText().length());
locationAnnotation.setSelectionContext(SINGLE_SENTENCE);
//create an Text Annotation representing an extracted Organisation
TextAnnotation orgAnnotation = factory.getProxy(
createEnhancementURI(), TextAnnotation.class);
orgAnnotation.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
orgAnnotation.setCreated(new Date());
orgAnnotation.setExtractedFrom(ciUri);
orgAnnotation.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/text#Organisation"));
orgAnnotation.setConfidence(0.78);
orgAnnotation.setSelectedText("University of Otago");
orgAnnotation.setStart(SINGLE_SENTENCE.indexOf(orgAnnotation.getSelectedText()));
orgAnnotation.setEnd(orgAnnotation.getStart()+orgAnnotation.getSelectedText().length());
orgAnnotation.setSelectionContext(SINGLE_SENTENCE);
// create an Entity Annotation for the person TextAnnotation
EntityAnnotation patrickMarshall = factory.getProxy(
createEnhancementURI(), EntityAnnotation.class);
patrickMarshall.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
patrickMarshall.setCreated(new Date());
patrickMarshall.setExtractedFrom(ciUri);
patrickMarshall.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/entity#Entity"));
patrickMarshall.setConfidence(0.56);
patrickMarshall.getRelations().add(personAnnotation);
patrickMarshall.setEntityLabel("Patrick Marshall");
patrickMarshall.setEntityReference(new UriRef("http://rdf.freebase.com/rdf/en/patrick_marshall"));
patrickMarshall.getEntityTypes().addAll(Arrays.asList(
new UriRef("http://rdf.freebase.com/ns/people.person"),
new UriRef("http://rdf.freebase.com/ns/common.topic"),
new UriRef("http://rdf.freebase.com/ns/education.academic")));
// and an other for New Zealand
EntityAnnotation newZealand = factory.getProxy(
createEnhancementURI(), EntityAnnotation.class);
newZealand.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
newZealand.setCreated(new Date());
newZealand.setExtractedFrom(ciUri);
newZealand.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/entity#Entity"));
newZealand.setConfidence(0.98);
newZealand.getRelations().add(locationAnnotation);
newZealand.setEntityLabel("New Zealand");
newZealand.setEntityReference(new UriRef("http://rdf.freebase.com/rdf/en/new_zealand"));
newZealand.getEntityTypes().addAll(Arrays.asList(
new UriRef("http://rdf.freebase.com/ns/location.location"),
new UriRef("http://rdf.freebase.com/ns/common.topic"),
new UriRef("http://rdf.freebase.com/ns/location.country")));
// and an other option for New Zealand
EntityAnnotation airNewZealand = factory.getProxy(
createEnhancementURI(), EntityAnnotation.class);
airNewZealand.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
airNewZealand.setCreated(new Date());
airNewZealand.setExtractedFrom(ciUri);
airNewZealand.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/entity#Entity"));
airNewZealand.setConfidence(0.36);
airNewZealand.getRelations().add(locationAnnotation);
airNewZealand.setEntityLabel("New Zealand");
airNewZealand.setEntityReference(new UriRef("http://rdf.freebase.com/rdf/en/air_new_zealand"));
airNewZealand.getEntityTypes().addAll(Arrays.asList(
new UriRef("http://rdf.freebase.com/ns/business.sponsor"),
new UriRef("http://rdf.freebase.com/ns/common.topic"),
new UriRef("http://rdf.freebase.com/ns/travel.transport_operator"),
new UriRef("http://rdf.freebase.com/ns/aviation.airline"),
new UriRef("http://rdf.freebase.com/ns/aviation.aircraft_owner"),
new UriRef("http://rdf.freebase.com/ns/business.employer"),
new UriRef("http://rdf.freebase.com/ns/freebase.apps.hosts.com.appspot.acre.juggle.juggle"),
new UriRef("http://rdf.freebase.com/ns/business.company")));
System.out.println("creation time "+(System.currentTimeMillis()-start)+"ms");
//now test the enhancement
int numberOfTextAnnotations = checkAllTextAnnotations(ci.getMetadata());
assertEquals(3, numberOfTextAnnotations);
int numberOfEntityAnnotations = checkAllEntityAnnotations(ci.getMetadata());
assertEquals(3, numberOfEntityAnnotations);
}