Package org.apache.stanbol.enhancer.engines.entitylinking

Examples of org.apache.stanbol.enhancer.engines.entitylinking.Entity


        //add some terms to the searcher
        MGraph graph = new IndexedMGraph();
        UriRef uri = new UriRef("urn:test:PatrickMarshall");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Patrick Marshall")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_PERSON));
        searcher.addEntity(new Entity(uri, graph));
       
        uri = new UriRef("urn:test:Geologist");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Geologist")));
        graph.add(new TripleImpl(uri, TYPE, new UriRef(NamespaceEnum.skos+"Concept")));
        graph.add(new TripleImpl(uri, REDIRECT, new UriRef("urn:test:redirect:Geologist")));
        searcher.addEntity(new Entity(uri, graph));
        //a redirect
        uri = new UriRef("urn:test:redirect:Geologist");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Geologe (redirect)")));
        graph.add(new TripleImpl(uri, TYPE, new UriRef(NamespaceEnum.skos+"Concept")));
        searcher.addEntity(new Entity(uri, graph));

        uri = new UriRef("urn:test:NewZealand");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("New Zealand")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_PLACE));
        searcher.addEntity(new Entity(uri, graph));

        uri = new UriRef("urn:test:UniversityOfOtago");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("University of Otago")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_ORGANISATION));
        searcher.addEntity(new Entity(uri, graph));
       
        uri = new UriRef("urn:test:University");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("University")));
        graph.add(new TripleImpl(uri, TYPE, new UriRef(NamespaceEnum.skos+"Concept")));
        searcher.addEntity(new Entity(uri, graph));

        uri = new UriRef("urn:test:Otago");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Otago")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_PLACE));
        searcher.addEntity(new Entity(uri, graph));
        //add a 2nd Otago (Place and University
        uri = new UriRef("urn:test:Otago_Texas");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Otago (Texas)")));
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Otago")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_PLACE));
        searcher.addEntity(new Entity(uri, graph));

        uri = new UriRef("urn:test:UniversityOfOtago_Texas");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("University of Otago (Texas)")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_ORGANISATION));
        searcher.addEntity(new Entity(uri, graph));
       
        TEST_ANALYSED_TEXT = AnalysedTextFactory.getDefaultInstance().createAnalysedText(
            ciFactory.createBlob(new StringSource(TEST_TEXT)));
        TEST_ANALYSED_TEXT_WO = AnalysedTextFactory.getDefaultInstance().createAnalysedText(
                ciFactory.createBlob(new StringSource(TEST_TEXT_WO)));
View Full Code Here


            for(Suggestion suggestion : linkedEntity.getSuggestions()){
                UriRef entityAnnotation = EnhancementEngineHelper.createEntityEnhancement(ci, this);
                //should we use the label used for the match, or search the
                //representation for the best label ... currently its the matched one
                PlainLiteral label = suggestion.getBestLabel(linkerConfig.getNameField(),language);
                Entity entity = suggestion.getEntity();
                metadata.add(new TripleImpl(entityAnnotation, Properties.ENHANCER_ENTITY_LABEL, label));
                metadata.add(new TripleImpl(entityAnnotation,ENHANCER_ENTITY_REFERENCE, entity.getUri()));
                Iterator<UriRef> suggestionTypes = entity.getReferences(linkerConfig.getTypeField());
                while(suggestionTypes.hasNext()){
                    metadata.add(new TripleImpl(entityAnnotation,
                        Properties.ENHANCER_ENTITY_TYPE, suggestionTypes.next()));
                }
                metadata.add(new TripleImpl(entityAnnotation,
                    Properties.ENHANCER_CONFIDENCE, literalFactory.createTypedLiteral(suggestion.getScore())));
                for(UriRef textAnnotation : textAnnotations){
                    metadata.add(new TripleImpl(entityAnnotation, Properties.DC_RELATION, textAnnotation));
                }
                //add origin information of the EntiySearcher
                for(Entry<UriRef,Collection<Resource>> originInfo : entitySearcher.getOriginInformation().entrySet()){
                    for(Resource value : originInfo.getValue()){
                        metadata.add(new TripleImpl(entityAnnotation,
                            originInfo.getKey(),value));
                    }
                }
                //in case dereferencing of Entities is enabled we need also to
                //add the RDF data for entities
                if(linkerConfig.isDereferenceEntitiesEnabled() &&
                        dereferencedEntitis.add(entity.getUri())){ //not yet dereferenced
                    //add all outgoing triples for this entity
                    //NOTE: do not add all triples as there might be other data in the graph
                    for(Iterator<Triple> triples = entity.getData().filter(entity.getUri(), null, null);
                            triples.hasNext();metadata.add(triples.next()));
                }
            }
        }
    }
View Full Code Here

        for(LinkedEntity comention : comentions){
            log.debug(" > {}",comention);
            //URIs of TextAnnotations for the initial mention of this co-mention
            Collection<UriRef> initialMentions = new ArrayList<UriRef>(comention.getSuggestions().size());
            for(Suggestion suggestion : comention.getSuggestions()){
                Entity entity = suggestion.getEntity();
                if(textAnnotations.contains(entity.getUri())){
//                if(entity.getData().filter(entity.getUri(),RDF_TYPE,ENHANCER_TEXTANNOTATION).hasNext()){
                    //this is a textAnnotation
                    initialMentions.add(entity.getUri());
                } //else TODO support also Entities!!
            }
            //create the TextAnnotations for the co-mention
            for(Occurrence occurrence : comention.getOccurrences()){
                Literal startLiteral = literalFactory.createTypedLiteral(occurrence.getStart());
View Full Code Here

     * @param nameField the field used to search for labels
     * @param language the language
     * @return the best match or {@link Suggestion#getMatchedLabel()} if non is found
     */
    public PlainLiteral getBestLabel(UriRef nameField, String language){
        Entity rep = getEntity();
        //start with the matched label -> so if we do not find a better one
        //we will use the matched!
        PlainLiteral matchedLabel = getMatchedLabel();
        PlainLiteral label = matchedLabel;
        // 1. check if the returned Entity does has a label -> if not return null
        // add labels (set only a single label. Use "en" if available!
        Iterator<PlainLiteral> labels = rep.getText(nameField);
        boolean matchFound = false;
        while (labels.hasNext() && !matchFound) {
            PlainLiteral actLabel = labels.next();
            if(label == null){
                label = actLabel;
View Full Code Here

        Arrays.sort(tokenResults,COLLECTION_SIZE_COMPARATOR);
        for(int i = 1; i < tokenResults.length && !join.isEmpty(); i++){
            Set<Entity> old = join;
            join = new HashSet<Entity>(); //new set to add all elements
            for(Iterator<Entity> it = tokenResults[i].iterator(); it.hasNext() && !old.isEmpty();){
                Entity e = it.next();
                if(old.remove(e)){
                    join.add(e);
                }
            }
        }
View Full Code Here

        //that some/all of the results do already redirects processed.
        //therefore there is a small internal state that stores this information
        if(suggestion.isRedirectedProcessed()){
            return; //Redirects for ResultMatch are already processed ... ignore
        }
        Entity result = suggestion.getResult();
        Iterator<UriRef> redirects = result.getReferences(linkerConfig.getRedirectField());
        switch (linkerConfig.getRedirectProcessingMode()) {
            case ADD_VALUES:
                TripleCollection entityData = result.getData();
                UriRef entityUri = result.getUri();
                while(redirects.hasNext()){
                    UriRef redirect = redirects.next();
                    if(redirect != null){
                        Entity redirectedEntity = entitySearcher.get(redirect,
                            linkerConfig.getSelectedFields());
                        if(redirectedEntity != null){
                            for(Iterator<Triple> data = redirectedEntity.getData().filter(
                                redirectedEntity.getUri(), null, null);data.hasNext();){
                                Triple t = data.next();
                                entityData.add(new TripleImpl(entityUri,t.getPredicate(),t.getObject()));
                            }
                        }
                        //set that the redirects where searched for this result
                        suggestion.setRedirectProcessed(true);
                    }
                }
            case FOLLOW:
                while(redirects.hasNext()){
                    UriRef redirect = redirects.next();
                    if(redirect != null){
                        Entity redirectedEntity = entitySearcher.get(redirect,
                            linkerConfig.getSelectedFields());
                        if(redirectedEntity != null){
                            suggestion.setRedirect(redirectedEntity);
                        }
                    }
View Full Code Here

            for(Suggestion suggestion : linkedEntity.getSuggestions()){
                UriRef entityAnnotation = EnhancementEngineHelper.createEntityEnhancement(ci, this);
                //should we use the label used for the match, or search the
                //representation for the best label ... currently its the matched one
                PlainLiteral label = suggestion.getBestLabel(linkerConfig.getNameField(),language);
                Entity entity = suggestion.getEntity();
                metadata.add(new TripleImpl(entityAnnotation, Properties.ENHANCER_ENTITY_LABEL, label));
                metadata.add(new TripleImpl(entityAnnotation,ENHANCER_ENTITY_REFERENCE, entity.getUri()));
                Iterator<UriRef> suggestionTypes = entity.getReferences(linkerConfig.getTypeField());
                while(suggestionTypes.hasNext()){
                    metadata.add(new TripleImpl(entityAnnotation,
                        Properties.ENHANCER_ENTITY_TYPE, suggestionTypes.next()));
                }
                metadata.add(new TripleImpl(entityAnnotation,
                    Properties.ENHANCER_CONFIDENCE, literalFactory.createTypedLiteral(suggestion.getScore())));
                for(UriRef textAnnotation : textAnnotations){
                    metadata.add(new TripleImpl(entityAnnotation, Properties.DC_RELATION, textAnnotation));
                }
                //add origin information of the EntiySearcher
                for(Entry<UriRef,Collection<Resource>> originInfo : entitySearcher.getOriginInformation().entrySet()){
                    for(Resource value : originInfo.getValue()){
                        metadata.add(new TripleImpl(entityAnnotation,
                            originInfo.getKey(),value));
                    }
                }
                //in case dereferencing of Entities is enabled we need also to
                //add the RDF data for entities
                if(linkerConfig.isDereferenceEntitiesEnabled() &&
                        dereferencedEntitis.add(entity.getUri())){ //not yet dereferenced
                    //add all outgoing triples for this entity
                    //NOTE: do not add all triples as there might be other data in the graph
                    for(Iterator<Triple> triples = entity.getData().filter(entity.getUri(), null, null);
                            triples.hasNext();metadata.add(triples.next()));
                }
            }
        }
    }
View Full Code Here

     * @param nameField the field used to search for labels
     * @param language the language
     * @return the best match or {@link Suggestion#getMatchedLabel()} if non is found
     */
    public PlainLiteral getBestLabel(UriRef nameField, String language){
        Entity rep = getEntity();
        //start with the matched label -> so if we do not find a better one
        //we will use the matched!
        PlainLiteral matchedLabel = getMatchedLabel();
        PlainLiteral label = matchedLabel;
        // 1. check if the returned Entity does has a label -> if not return null
        // add labels (set only a single label. Use "en" if available!
        Iterator<PlainLiteral> labels = rep.getText(nameField);
        boolean matchFound = false;
        while (labels.hasNext() && !matchFound) {
            PlainLiteral actLabel = labels.next();
            if(label == null){
                label = actLabel;
View Full Code Here

        //that some/all of the results do already redirects processed.
        //therefore there is a small internal state that stores this information
        if(suggestion.isRedirectedProcessed()){
            return; //Redirects for ResultMatch are already processed ... ignore
        }
        Entity result = suggestion.getResult();
        Iterator<UriRef> redirects = result.getReferences(linkerConfig.getRedirectField());
        switch (linkerConfig.getRedirectProcessingMode()) {
            case ADD_VALUES:
                MGraph entityData = result.getData();
                UriRef entityUri = result.getUri();
                while(redirects.hasNext()){
                    UriRef redirect = redirects.next();
                    if(redirect != null){
                        Entity redirectedEntity = entitySearcher.get(redirect,
                            linkerConfig.getSelectedFields());
                        if(redirectedEntity != null){
                            for(Iterator<Triple> data = redirectedEntity.getData().filter(
                                redirectedEntity.getUri(), null, null);data.hasNext();){
                                Triple t = data.next();
                                entityData.add(new TripleImpl(entityUri,t.getPredicate(),t.getObject()));
                            }
                        }
                        //set that the redirects where searched for this result
                        suggestion.setRedirectProcessed(true);
                    }
                }
            case FOLLOW:
                while(redirects.hasNext()){
                    UriRef redirect = redirects.next();
                    if(redirect != null){
                        Entity redirectedEntity = entitySearcher.get(redirect,
                            linkerConfig.getSelectedFields());
                        if(redirectedEntity != null){
                            suggestion.setRedirect(redirectedEntity);
                        }
                    }
View Full Code Here

        //add some terms to the searcher
        MGraph graph = new IndexedMGraph();
        UriRef uri = new UriRef("urn:test:PatrickMarshall");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Patrick Marshall")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_PERSON));
        searcher.addEntity(new Entity(uri, graph));
       
        uri = new UriRef("urn:test:Geologist");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Geologist")));
        graph.add(new TripleImpl(uri, TYPE, new UriRef(NamespaceEnum.skos+"Concept")));
        graph.add(new TripleImpl(uri, REDIRECT, new UriRef("urn:test:redirect:Geologist")));
        searcher.addEntity(new Entity(uri, graph));
        //a redirect
        uri = new UriRef("urn:test:redirect:Geologist");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Geologe (redirect)")));
        graph.add(new TripleImpl(uri, TYPE, new UriRef(NamespaceEnum.skos+"Concept")));
        searcher.addEntity(new Entity(uri, graph));

        uri = new UriRef("urn:test:NewZealand");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("New Zealand")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_PLACE));
        searcher.addEntity(new Entity(uri, graph));

        uri = new UriRef("urn:test:UniversityOfOtago");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("University of Otago")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_ORGANISATION));
        searcher.addEntity(new Entity(uri, graph));
       
        uri = new UriRef("urn:test:University");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("University")));
        graph.add(new TripleImpl(uri, TYPE, new UriRef(NamespaceEnum.skos+"Concept")));
        searcher.addEntity(new Entity(uri, graph));

        uri = new UriRef("urn:test:Otago");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Otago")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_PLACE));
        searcher.addEntity(new Entity(uri, graph));
        //add a 2nd Otago (Place and University
        uri = new UriRef("urn:test:Otago_Texas");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Otago (Texas)")));
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("Otago")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_PLACE));
        searcher.addEntity(new Entity(uri, graph));

        uri = new UriRef("urn:test:UniversityOfOtago_Texas");
        graph.add(new TripleImpl(uri, NAME, new PlainLiteralImpl("University of Otago (Texas)")));
        graph.add(new TripleImpl(uri, TYPE, OntologicalClasses.DBPEDIA_ORGANISATION));
        searcher.addEntity(new Entity(uri, graph));
       
        Value<PhraseTag> nounPhrase = Value.value(new PhraseTag("NP",LexicalCategory.Noun),1d);
        TEST_ANALYSED_TEXT = AnalysedTextFactory.getDefaultInstance().createAnalysedText(
                ciFactory.createBlob(new StringSource(TEST_TEXT)));
        TEST_ANALYSED_TEXT.addSentence(0, TEST_ANALYSED_TEXT.getEnd());
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.engines.entitylinking.Entity

Copyright © 2018 www.massapicom. 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.