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

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


    /**
     * Tests the feature to remove one and the same natural language text for multiple languages
     */
    public void testRemoveNaturalLanguageValueInMultipleLanguages() {
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = createRepresentation(null);
        // 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


    }

    @Test
    public void testRemoveAllTextsOfALanguage() {
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = initNaturalLanguageTest(field);
        Set<String> textSet = new HashSet<String>(NL_TEST_all);
        // remove all texts of a specific language
        rep.removeAllNaturalText(field, "en");
        for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next()
                .getText()))
            ;
        assertTrue(textSet.size() == 2);
        assertTrue(textSet.remove(NL_TEST_en2));
        assertTrue(textSet.remove(NL_TEST_en));
View Full Code Here

    @Test
    public void testRemoveAllTextsOfMultipleLanguages() {
        // remove all texts of multiple languages
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = initNaturalLanguageTest(field);
        Set<String> textSet = new HashSet<String>(NL_TEST_all);
        rep.removeAllNaturalText(field, "de", "de-AT");
        for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next()
                .getText()))
            ;
        assertTrue(textSet.size() == 2);
        assertTrue(textSet.remove(NL_TEST_de));
        assertTrue(textSet.remove(NL_TEST_de_AT));
View Full Code Here

    }

    @Test
    public void testRemoveAllTextsWithNullLanguage() {
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = initNaturalLanguageTest(field);
        Set<String> textSet = new HashSet<String>(NL_TEST_all);
        // test removal of null language
        rep.removeAllNaturalText(field, (String) null);
        for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next()
                .getText()))
            ;
        assertTrue(textSet.size() == 2);
        assertTrue(textSet.remove(NL_TEST_noLang));
        assertTrue(textSet.remove(NL_TEST_string)); // and this should be the stringTest
View Full Code Here

    }

    @Test
    public void testRemoveAllNaturalLanguageValues() {
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = initNaturalLanguageTest(field);
        // add a reference to ensure that only texts (and strings) are removed
        String testReference = "http://www.test.org/test";
        rep.addReference(field, testReference);
        // test removal of all natural language values by parsing no languages
        rep.removeAllNaturalText(field);
        Iterator<Text> texts = rep.get(field, (String[]) null);
        assertFalse(texts.hasNext()); // not texts any more
        assertTrue(rep.get(field).hasNext()); // but still a reference!
    }
View Full Code Here

    }

    @Test
    public void testRemoveAllNaturalLanguageValuesByParsingAnEmptyArray() {
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = initNaturalLanguageTest(field);
        // add a reference to ensure that only texts (and strings) are removed
        String testReference = "http://www.test.org/test";
        rep.addReference(field, testReference);
        // test removal of all natural language values by parsing an empty language array
        rep.removeAllNaturalText(field, new String[] {});
        Iterator<Text> texts = rep.get(field, (String[]) null);
        assertFalse(texts.hasNext());
        assertTrue(rep.get(field).hasNext()); // text of the added reference is still present
    }
View Full Code Here

        Float maxExactScore = null;
        List<Suggestion> matches = new ArrayList<Suggestion>(numSuggestions);
        // assumes entities are sorted by score
        for (Iterator<Entity> guesses = results.iterator(); guesses.hasNext();) {
            Suggestion match = new Suggestion(guesses.next());
            Representation rep = match.getEntity().getRepresentation();
            Float score = rep.getFirst(RdfResourceEnum.resultScore.getUri(), Float.class);
            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
View Full Code Here

    }

    @Test
    public void testRemoveAllNaturalLanguageValuesByParsingNullAsLanguageArray() {
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = initNaturalLanguageTest(field);
        // add a reference to ensure that only texts (and strings) are removed
        String testReference = "http://www.test.org/test";
        rep.addReference(field, testReference);
        // test removal of all natural language values by parsing only a single argument
        rep.removeAllNaturalText(field);
        Iterator<Text> texts = rep.get(field, (String[]) null);
        assertFalse(texts.hasNext());
        assertTrue(rep.get(field).hasNext()); // text of the added reference is still present
    }
View Full Code Here

        testRepresentation("");
    }

    @Test
    public void testMultipleInstanceForSameID() {
        Representation rep = testRepresentation("urn:testSameId");
        Representation rep1 = testRepresentation("urn:testSameId");
        // check that multiple calls with the same ID create different instances
        // -> this is very important to allow mapping of Representations (e.g.
        // when they are stored within a cache
        assertNotSame(rep, rep1);
        // if an ID is parsed, than the two instance should be equal
        assertTrue(rep.equals(rep1));
        assertTrue(rep.hashCode() == rep1.hashCode()); // check the hash code
    }
View Full Code Here

        assertTrue(rep.hashCode() == rep1.hashCode()); // check the hash code
    }

    private Representation testRepresentation(String id) {
        ValueFactory vf = getValueFactory();
        Representation rep = vf.createRepresentation(id);
        assertNotNull(rep);
        assertNotNull(rep.getId());
        if (id != null) {
            assertEquals(rep.getId(), id);
        }
        return rep;
    }
View Full Code Here

TOP

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

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.