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

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


        //now test, that the Plain Literals are available as natural language
        //tests via the Representation Interface!
        //1) one without a language
        Iterator<Text> noLangaugeTexts = rep.get(field, (String)null);
        assertTrue(noLangaugeTexts.hasNext());
        Text noLanguageText = noLangaugeTexts.next();
        assertEquals(noLangLiteral.getLexicalForm(), noLanguageText.getText());
        assertNull(noLanguageText.getLanguage());
        assertFalse(noLangaugeTexts.hasNext()); //only a single result
        //2) one with a language
        Iterator<Text> enLangaugeTexts = rep.get(field, "en");
        assertTrue(enLangaugeTexts.hasNext());
        Text enLangageText = enLangaugeTexts.next();
        assertEquals(enLiteral.getLexicalForm(), enLangageText.getText());
        assertEquals(enLiteral.getLanguage().toString(), enLangageText.getLanguage());
        assertFalse(enLangaugeTexts.hasNext());//only a single result
        //3) test to get all natural language values
        Set<String> stringValues = new HashSet<String>();
        for(PlainLiteral plainLiteral : plainLiterals){
            stringValues.add(plainLiteral.getLexicalForm());
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

    public Collection<Object> listSubjects(Object property, Object object) {
        FieldQuery query = createQuery();
        if(this.isURI(object)){
            query.setConstraint(property.toString(), new ReferenceConstraint(object.toString()));
        } else if(object instanceof Text){
            Text text = (Text)object;
            TextConstraint constraint;
            if(text.getLanguage() == null){
                constraint = new TextConstraint(text.getText(), PatternType.none, true);
            } else {
                constraint = new TextConstraint(text.getText(), PatternType.none, true,text.getLanguage());
            }
            query.setConstraint(property.toString(), constraint);
        } else {
            Set<DataTypeEnum> dataTypes = DataTypeEnum.getPrimaryDataTypes(object.getClass());
            if(dataTypes == null || dataTypes.isEmpty()){
View Full Code Here

                JSONObject jResult = new JSONObject();
                jResult.put("id", r.getId());
                double similarity = 0.0;
                String name = null; //the name returned for the entity
                for(Iterator<Text> labels = r.getText(NAME_FIELD);labels.hasNext();){
                    Text label = labels.next();
                    if(label.getText().equalsIgnoreCase(rQuery.getQuery())){
                        name = label.getText();
                        similarity = 1.0;
                        break;
                    }
                    double curSimilarity = Utils.levenshtein(rQuery.getQuery(), label.getText());
                    if(similarity < curSimilarity){
                        name = label.getText();
                        similarity = curSimilarity;
                    }
                }
                //set the selected name
                jResult.put("name", name);
View Full Code Here

            List<String> postalCodes = new ArrayList<String>();
            List<URL> wikipediaLinks = new ArrayList<URL>();
            List<Text> shortNames = new ArrayList<Text>();
            for(FeatureName name : alternateNames){
                if(name.isNaturalLanguageLabel()){
                    Text act = vf.createText(name.getName(),name.getLang());
                    if(name.isPreferred()){
                        officialList.add(act);
                    } else {
                        altList.add(act);
                    }
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(this.label.getText().equalsIgnoreCase(label.getText())){
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

            if (maxScore == null) {
                maxScore = score;
            }
            Iterator<Text> labels = rep.getText(nameField);
            while (labels.hasNext() && match.getLevenshtein() < 1.0) {
                Text label = labels.next();
                if (language == null || // if the content language is unknown ->
                                        // accept all labels
                    label.getLanguage() == null || // accept labels with no
                                                   // language
                    // and labels in the same language as the content
                    (language != null && label.getLanguage().startsWith(language))) {
                    double actMatch = levenshtein(
                        casesensitive ? label.getText() : label.getText().toLowerCase(), namedEntityLabel);
                    if (actMatch > match.getLevenshtein()) {
                        match.setLevenshtein(actMatch);
                        match.setMatchedLabel(label);
                    }
                }
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

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.