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

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


    public void testMultipleAddAndRemove() throws MalformedURLException, URISyntaxException {
        String field = "urn:the.field:used.for.this.Test";
        ValueFactory vf = getValueFactory();
        Representation rep = createRepresentation(null);
        Reference ref = vf.createReference("http://www.test.org/test");
        Text text = vf.createText("test", "en");
        Integer i = 42;
        Double d = Math.PI;
        URI uri = new URI("http://www.test.org/uriTest");
        URL url = new URL("http://www.test.org/urlTest");
        String[] textAsArray = new String[] {"Test text as Array", "en"};
View Full Code Here


    public void testGetNaturalTextWithNoLanguage() {
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = initNaturalLanguageTest(field);
        // Note that also String values need to be converted to texts with no language
        Set<String> textSet = new HashSet<String>(NL_TEST_all);
        Text text;
        Iterator<Text> noLangTexts = rep.get(field, (String) null);
        assertNotNull(noLangTexts);
        while (noLangTexts.hasNext()) {
            text = noLangTexts.next();
            assertNull(text.getLanguage());
            assertTrue(textSet.remove(text.getText()));
        }
        assertTrue(textSet.size() == 4); // check that both text where found
    }
View Full Code Here

        Representation rep = initNaturalLanguageTest(field);
        // test de texts
        Iterator<Text> deTexts = rep.get(field, "de");
        assertNotNull(deTexts);
        assertTrue(deTexts.hasNext()); // there is one German text in the test set
        Text text = deTexts.next();
        assertEquals(text.getLanguage(), "de"); // "de" lang
        assertEquals(text.getText(), NL_TEST_de); // the de lang text
        assertFalse(deTexts.hasNext());// only one Result
        // test en labels (2 results)
        Iterator<Text> enTexts = rep.get(field, "en");
        assertNotNull(enTexts);
        Set<String> textSet = new HashSet<String>(Arrays.asList(NL_TEST_en, NL_TEST_en2));
        while (enTexts.hasNext()) {
            text = enTexts.next();
            assertEquals("en", text.getLanguage());
            assertTrue(textSet.remove(text.getText())); // remove the found
        }
        assertTrue(textSet.isEmpty()); // all texts found
    }
View Full Code Here

        // test multiple language query
        Iterator<Text> allDeTexts = rep.get(field, "de", "de-AT");
        assertNotNull(allDeTexts);
        Set<String> textSet = new HashSet<String>(Arrays.asList(NL_TEST_de, NL_TEST_de_AT));
        while (allDeTexts.hasNext()) {
            Text text = allDeTexts.next();
            assertTrue(text.getLanguage().equalsIgnoreCase("de") ||
                text.getLanguage().equalsIgnoreCase("de-AT"));
            assertTrue(textSet.remove(text.getText())); // remove the found
        }
        assertTrue(textSet.isEmpty()); // all texts found
    }
View Full Code Here

        String[] languageArray = new String[] {"en", "de", null};
        rep.addNaturalText(field, NL_TEST_noLang, languageArray);
        Set<String> languages = new HashSet<String>(Arrays.asList(languageArray));
        Iterator<Text> texts = rep.get(field, (String[]) null);
        while (texts.hasNext()) {
            Text text = texts.next();
            assertTrue(languages.remove(text.getLanguage()));
            assertEquals(NL_TEST_noLang, text.getText());
        }
        assertTrue(languages.isEmpty());
    }
View Full Code Here

        // add the same label for multiple languages
        rep.addNaturalText(field, NL_TEST_noLang, "en", "de", null);
        rep.removeNaturalText(field, NL_TEST_noLang, "en", null);
        Iterator<Text> texts = rep.get(field, (String[]) null);
        assertTrue(texts.hasNext());
        Text text = texts.next();
        assertFalse(texts.hasNext());
        assertEquals("de", text.getLanguage());
        assertEquals(NL_TEST_noLang, text.getText());
    }
View Full Code Here

     *            the language
     * @return the created {@link Text} instance that can be used to perform further tests.
     */
    private Text testText(String textString, String language) {
        ValueFactory vf = getValueFactory();
        Text text = vf.createText(textString, language);
        assertNotNull(text.getText());
        assertNotNull(text.getText());
        assertEquals(text.getText(), textString);
        if (language == null) {
            assertTrue(text.getLanguage() == null);
        } else if (language.isEmpty()) {
            // implementations are free to change an empty language string to null
            // NOTE that it is not allowed to change NULL to an empty String!
            assertTrue(text.getLanguage() == null || text.getLanguage().isEmpty());
        } else {
            assertNotNull(text.getLanguage());
            assertEquals(text.getLanguage(), language);
        }
        return text;
    }
View Full Code Here

        }

        @Override
        public Text adapt(Object value, Class<Text> type) {
            if(value instanceof Text){
                Text text = (Text)value;
                if(languages == null || languages.contains(text.getLanguage())){
                    return text;
                } else { //language does not fit -> filter
                    return null;
                }
            } else if(isNullLanguage && value instanceof String){
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

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.