Examples of RdfEntityFactory


Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

public class RdfEntityFactoryTest {

    @Test
    public void testRdfEntity() throws Exception {
        MGraph graph = new SimpleMGraph();
        RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
        String testUri = "urn:RdfEntityFactoryTest:TestEntity";
        UriRef node = new UriRef(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());
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

        assertEquals(rdfEntity.hashCode(), rdfEntity2.hashCode());
    }
    @Test
    public void testPrimitiveDataTypes() throws Exception {
        MGraph graph = new SimpleMGraph();
        RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
        String testUri = "urn:RdfEntityFactoryTest:TestEntity";
        UriRef node = new UriRef(testUri);
        TestRdfEntity testEntity = factory.getProxy(node, TestRdfEntity.class);

        testEntity.setBoolean(true);
        assertTrue(testEntity.getBoolean());

        testEntity.setInteger(10);
View Full Code Here

Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

    }

    @Test
    public void testTypeStatements() throws Exception {
        MGraph graph = new SimpleMGraph();
        RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
        String testUri = "urn:RdfEntityFactoryTest:TestEntity";
        UriRef node = new UriRef(testUri);
        TestRdfEntity entity = factory.getProxy(node, TestRdfEntity.class, new Class[]{TestRdfEntity2.class});
        // test the if the proxy implements both interfaces
        assertTrue(entity instanceof TestRdfEntity);
        assertTrue(entity instanceof TestRdfEntity2);

        Set<String> typeStrings = getRdfTypes(graph, node);
View Full Code Here

Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

    }

    @Test
    public void testObjectProperties() throws Exception {
        MGraph graph = new SimpleMGraph();
        RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
        String testUri = "urn:RdfEntityFactoryTest:TestEntity";
        String testUri2 = "urn:RdfEntityFactoryTest:TestEntity2";
        UriRef node = new UriRef(testUri);
        UriRef node2 = new UriRef(testUri2);
        TestRdfEntity entity = factory.getProxy(node, TestRdfEntity.class);
        TestRdfEntity2 entity2 = factory.getProxy(node2, TestRdfEntity2.class);

        URI testURI = new URI("urn:test:URI");
        entity.setURI(testURI);
        assertEquals(testURI, entity.getURI());

        URL testURL = new URL("http://www.iks-project.eu");
        entity.setURL(testURL);
        assertEquals(testURL, entity.getURL());

        entity.setUriRef(node2);
        assertEquals(node2, entity.getUriRef());

        entity2.setTestEntity(entity);
        assertEquals(entity, entity2.getTestEntity());

        Collection<TestRdfEntity> testEntities = entity2.getTestEntities();
        assertTrue(testEntities.isEmpty()); //check that entity is not in the collection
        Set<UriRef> testUriRefs = new HashSet<UriRef>();
        int NUM = 10;
        for (int i=0;i<NUM;i++){
            UriRef testNode = new UriRef(testUri+':'+'_'+i);
            testUriRefs.add(testNode);
            testEntities.add(factory.getProxy(testNode, TestRdfEntity.class));
        }
        //now get a new collection and test if the added entities are there
        Collection<UriRef> resultUriRefs = new ArrayList<UriRef>(); //add to a list to check for duplicates
        for (TestRdfEntity e : entity2.getTestEntities()){
            assertTrue(e.getId() instanceof UriRef); //I used UriRefs for the generation ...
View Full Code Here

Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

    }

    @Test
    public void testInterfaceHierarchies() throws Exception {
        MGraph graph = new SimpleMGraph();
        RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
        String testUri = "urn:RdfEntityFactoryTest:SubTestEntity";
        String testUri2 = "urn:RdfEntityFactoryTest:TestEntity2";
        String testUri3 = "urn:RdfEntityFactoryTest:TestEntity";
        UriRef node = new UriRef(testUri);
        UriRef node2 = new UriRef(testUri2);
        UriRef node3 = new UriRef(testUri3);
        SubTestRdfEntity entity = factory.getProxy(node, SubTestRdfEntity.class);
        TestRdfEntity entity2 = factory.getProxy(node2, TestRdfEntity.class,new Class<?>[]{SubTestRdfEntity.class,TestRdfEntity2.class});
        TestRdfEntity entity3 = factory.getProxy(node3, TestRdfEntity.class);

        //Start with checking the types for entity2
        //first type cast to the hierarchy
        assertTrue(entity instanceof TestRdfEntity);
        assertTrue(entity instanceof RdfEntity);

        // test if the rdf:type triples are present in the MGraph
        Set<String> typeStrings = getRdfTypes(graph, node);
        assertTrue(typeStrings.contains(SubTestRdfEntity.class.getAnnotation(Rdf.class).id()));
        assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));

        typeStrings = null;
        //now the same for entity2
        //first type cast to the hierarchy
        assertTrue(entity2 instanceof SubTestRdfEntity);
        assertTrue(entity2 instanceof TestRdfEntity2);
        assertTrue(entity2 instanceof RdfEntity);

        // test if the rdf:type triples are present in the MGraph
        typeStrings = getRdfTypes(graph, node2);
        assertTrue(typeStrings.contains(SubTestRdfEntity.class.getAnnotation(Rdf.class).id()));
        assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));
        assertTrue(typeStrings.contains(TestRdfEntity2.class.getAnnotation(Rdf.class).id()));

        typeStrings = null;
        //Now check Entity3
        assertTrue(!(entity3 instanceof SubTestRdfEntity));
        assertTrue(entity3 instanceof TestRdfEntity);

        //Now create an new Entity for the same Node that implements SubEntity2
        SubTestRdfEntity entity4 = factory.getProxy(node3, SubTestRdfEntity.class);
        //check if entity4 implements SubTestRefEntity
        assertTrue(entity4 instanceof SubTestRdfEntity);

        //now check if the additional type was added to node3
        typeStrings = getRdfTypes(graph, node3);
View Full Code Here

Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

            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 UriRef("urn:iks-project:enhancer:test:text-annotation:"+randomUUID()), TextAnnotation.class);
        textAnnotation.setCreator(new UriRef("urn:iks-project:enhancer:test:dummyEngine"));
        textAnnotation.setCreated(new Date());
        textAnnotation.setSelectedText(name);
        textAnnotation.setSelectionContext(context);
View Full Code Here

Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

    @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"));
View Full Code Here

Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

            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 UriRef("urn:iks-project:enhancer:test:text-annotation:"+randomUUID()), TextAnnotation.class);
        textAnnotation.setCreator(new UriRef("urn:iks-project:enhancer:test:dummyEngine"));
        textAnnotation.setCreated(new Date());
        textAnnotation.setSelectedText(name);
        textAnnotation.setSelectionContext(context);
View Full Code Here

Examples of org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory

            content = IOUtils.toString(ci.getStream(),"UTF-8");
        } catch (IOException e) {
            //should never happen anyway!
            content = "";
        }
        RdfEntityFactory factory = RdfEntityFactory.createInstance(ci.getMetadata());
        TextAnnotation testAnnotation = factory.getProxy(new UriRef("urn:org.apache:stanbol.enhancer:test:text-annotation:person"), TextAnnotation.class);
        testAnnotation.setCreator(new UriRef("urn:org.apache:stanbol.enhancer:test:dummyEngine"));
        testAnnotation.setCreated(new Date());
        testAnnotation.setSelectedText(name);
        testAnnotation.setSelectionContext(context);
        testAnnotation.getDcType().add(type);
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.helper.RdfEntityFactory

public class RdfEntityFactoryTest {

    @Test
    public void testRdfEntity() throws Exception {
        MGraph graph = new SimpleMGraph();
        RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
        String testUri = "urn:RdfEntityFactoryTest:TestEntity";
        UriRef node = new UriRef(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());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.