Package org.apache.stanbol.entityhub.servicesapi.model

Examples of org.apache.stanbol.entityhub.servicesapi.model.Text


                                               String nameField,
                                               String lang) {
        Representation rep = suggestion.getEntity().getRepresentation();
        // 1. extract the "best label"
        //Start with the matched one
        Text label = suggestion.getMatchedLabel();
        //if the matched label is not in the requested language
        boolean langMatch = (lang == null && label.getLanguage() == null) ||
                (label.getLanguage() != null && label.getLanguage().startsWith(lang));
            //search if a better label is available for this Entity
        if(!langMatch){
            Iterator<Text> labels = rep.getText(nameField);
            while (labels.hasNext() && !langMatch) {
                Text actLabel = labels.next();
                langMatch = (lang == null && actLabel.getLanguage() == null) ||
                        (actLabel.getLanguage() != null && actLabel.getLanguage().startsWith(lang));
                if(langMatch){ //if the language matches ->
                    //override the matched label
                    label = actLabel;
                }
            }
View Full Code Here


                    entity = referencedSiteManager.getEntity(topic.conceptUri);
                }
                if (entity != null) {
                    Representation representation = entity.getRepresentation();
                    // TODO: extract all languages based on some configuration instead of hardcoding English
                    Text label = representation.getFirst(NamespaceEnum.skos + "prefLabel", "en", "en-US",
                        "en-GB");
                    if (label == null) {
                        label = representation.getFirst(NamespaceEnum.rdfs + "label", "en", "en-US", "en-GB");
                    }
                    if (label != null) {
                        metadata.add(new TripleImpl(enhancement,
                                org.apache.stanbol.enhancer.servicesapi.rdf.Properties.ENHANCER_ENTITY_LABEL,
                                new PlainLiteralImpl(label.getText())));
                    }
                }
            }
        } catch (ClassifierException e) {
            throw new EngineException(e);
View Full Code Here

     * @return <code>true</code> if a label was acceptable or <code>false</code>
     * if no label was found
     */
    private boolean checkLabels(Iterator<Text> labels, String language, List<String> searchTokens) {
        while(labels.hasNext()){
            Text label = labels.next();
            //NOTE: I use here startWith language because I want 'en-GB' labels accepted for 'en'
            if(label.getLanguage() == null || label.getLanguage().startsWith(language)){
                String text = label.getText().toLowerCase();
                if(searchTokens.size() > 1){
                    int foundTokens = 0;
                    for(String token : searchTokens){
                        if(text.indexOf(token.toLowerCase())>=0){
                            foundTokens++;
View Full Code Here

        for(Iterator<String> fields = rep.getFieldNames();fields.hasNext();){
            String field = fields.next();
            Iterator<Text> values = rep.getText(field);
//            assertTrue(values.hasNext());
            while(values.hasNext()){
                Text text = values.next();
                assertNotNull(text);
                String lang = text.getLanguage();
                //log.info(text.getText()+" | "+text.getLanguage()+" | "+text.getText().endsWith("@"+lang));
                //this texts that the text does not contain the @{lang} as added by
                //the toString method of the RDF Literal java class
                assertFalse("Labels MUST NOT end with the Language! value="+text.getText(),
                    text.getText().endsWith("@"+lang));
            }
        }
    }
View Full Code Here

                maxScore = rep.getFirst(RdfResourceEnum.resultScore.getUri(),Float.class);
            }
            Iterator<Text> labels = rep.getText(nameField);
            boolean found = false;
            while(labels.hasNext() && !found){
                Text label = labels.next();
                if(label.getLanguage() == null || label.getLanguage().startsWith("en")){
                    if(label.getText().equalsIgnoreCase(namedEntity.getName())){
                        found = true;
                    }
                }
            }
            if(found){
View Full Code Here

                                               Collection<NonLiteral> relatedEnhancements,
                                               Representation rep,
                                               String nameField) {
        // 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!
        Text label = null;
        Iterator<Text> labels = rep.getText(nameField);
        while (labels.hasNext()) {
            Text actLabel = labels.next();
            if (label == null) {
                label = actLabel;
            } else {
                //use startWith to match also en-GB and en-US ...
                if (actLabel.getLanguage() != null && actLabel.getLanguage().startsWith("en")) {
                    label = actLabel;
                }
            }
        }
        if (label == null) {
View Full Code Here

     */
    public Text getBestLabel(String nameField, String language){
        Representation rep = getRepresentation();
        //start with the matched label -> so if we do not find a better one
        //we will use the matched!
        Text label = this.label;
        // 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<Text> labels = rep.getText(nameField);
        boolean matchFound = false;
        while (labels.hasNext() && !matchFound) {
            Text actLabel = labels.next();
            if (label == null) { //take any label at first
                label = actLabel;
            }
            //now we have already a label check the language
            String actLang = actLabel.getLanguage();
            //use startWith to match also en-GB and en-US ...
            if (actLang != null && actLang.startsWith(language)) {
                //prefer labels with the correct language
                label = actLabel;
                if(label.getText().equalsIgnoreCase(label.getText())){
View Full Code Here

            //now the EntityAnnotations for the Suggestions
            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
                Text label = suggestion.getBestLabel(linkerConfig.getNameField(),language);
                metadata.add(new TripleImpl(entityAnnotation,
                    Properties.ENHANCER_ENTITY_LABEL,
                    label.getLanguage() == null ?
                            new PlainLiteralImpl(label.getText()) :
                                new PlainLiteralImpl(label.getText(),
                                    new Language(label.getLanguage()))));
                metadata.add(new TripleImpl(entityAnnotation,
                    Properties.ENHANCER_ENTITY_REFERENCE,
                    new UriRef(suggestion.getRepresentation().getId())));
                Iterator<Reference> suggestionTypes = suggestion.getRepresentation().getReferences(linkerConfig.getTypeField());
                while(suggestionTypes.hasNext()){
View Full Code Here

   
    public void addEntity(Representation rep){
        entities.put(rep.getId(), rep);
        Iterator<Text> labels = rep.getText(nameField);
        while(labels.hasNext()){
            Text label = labels.next();
            for(String token : tokenizer.tokenize(label.getText())){
                Collection<Representation> values = data.get(token);
                if(values == null){
                    values = new ArrayList<Representation>();
                    data.put(label.getText(), values);
                }
                values.add(rep);
            }
        }
       
View Full Code Here

        Iterator<Text> labels = rep.getText(config.getNameField());
        Suggestion match = new Suggestion(rep);
        Collection<Text> defaultLabels = new ArrayList<Text>();
        boolean matchedCurLangLabel = false;
        while(labels.hasNext()){
            Text label = labels.next();
            String lang = label.getLanguage();
            if((lang == null && curLang == null) ||
                    (lang != null && curLang != null && lang.startsWith(curLang))){
                matchLabel(match, label);
                matchedCurLangLabel = true;
            } else if((lang ==null && defLang == null) ||
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.model.Text

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.