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

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


        filter = new FieldValueFilter(nsPrefixProvider,"skos:releated", "*;!;!foaf:Person");
        Assert.assertNull(filter.process(r));
    }

    private Representation getRepresentation(String...types){
        Representation r = vf.createRepresentation("urn:test");
        for(String type : types){
            r.add(NamespaceEnum.rdf+"type", vf.createReference(type));
        }
        return r;
    }
View Full Code Here


            throw new YardException("Error while getting SolrDocument for id" + id, e);
        } catch (IOException e) {
            throw new YardException("Unable to access SolrServer", e);
        }
        long retrieve = System.currentTimeMillis();
        Representation rep;
        if (doc != null) {
            // create an Representation for the Doc! retrieve
            log.debug(String.format("Create Representation %s from SolrDocument",
                doc.getFirstValue(fieldMapper.getDocumentIdField())));
            rep = createRepresentation(doc, null);
View Full Code Here

        if (id == null) {
            throw new IllegalStateException(String.format(
                "The parsed Solr Document does not contain a value for the %s Field!",
                fieldMapper.getDocumentIdField()));
        }
        Representation rep = getValueFactory().createRepresentation(id.toString());
        for (String fieldName : doc.getFieldNames()) {
            IndexField indexField = fieldMapper.getField(fieldName);
            if (indexField != null && indexField.getPath().size() == 1) {
                String lang = indexField.getLanguages().isEmpty() ? null : indexField.getLanguages()
                        .iterator().next();
                if (fields == null || fields.contains(indexField.getPath().get(0))) {
                    for (Object value : doc.getFieldValues(fieldName)) {
                        if (value != null) {
                            IndexDataTypeEnum dataTypeEnumEntry = IndexDataTypeEnum.forIndexType(indexField
                                    .getDataType());
                            if (dataTypeEnumEntry != null) {
                                Object javaValue = indexValueFactory.createValue(
                                    dataTypeEnumEntry.getJavaType(), indexField.getDataType(), value, lang);
                                if (javaValue != null) {
                                    rep.add(indexField.getPath().iterator().next(), javaValue);
                                } else {
                                    log.warn(String.format("java value=null for index value %s", value));
                                }
                            } else {
                                log.warn(String.format(
View Full Code Here

            addCORSOrigin(servletContext, builder, headers);
            return builder.build();
        }
        //(1) if an id is parsed we need to ignore all other representations
        if(id != null && !"*".equals(id)){
            Representation r = parsed.get(id);
            if(r == null){
                ResponseBuilder builder = Response.status(Status.BAD_REQUEST)
                .entity(String.format("Parsed RDF data do not contain any "
                    + "Information about the parsed id '%s'",id))
                    .header(HttpHeaders.ACCEPT, accepted);
View Full Code Here

    @Test
    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"};
        Collection<Object> values = Arrays.asList(ref, text, i, d);
        Collection<Object> convertedValues = Arrays.asList((Object) url, uri, textAsArray);
        Collection<Object> allValues = Arrays.asList(ref, text, i, d, uri, url, textAsArray);
        // test adding of collections
        rep.add(field, values);
        assertTrue(asCollection(rep.get(field)).size() == 4);
        rep.remove(field, values);
        assertFalse(rep.get(field).hasNext());
        // test adding of Iterators
        rep.add(field, values.iterator());
        assertTrue(asCollection(rep.get(field)).size() == 4);
        rep.remove(field, values.iterator());
        assertFalse(rep.get(field).hasNext());
        // test adding of Enumerations
        Vector<Object> v = new Vector<Object>(values);
        rep.add(field, v.elements());
        assertTrue(asCollection(rep.get(field)).size() == 4);
        rep.remove(field, v.elements());
        assertFalse(rep.get(field).hasNext());
        // test adding and removing elements that need to be converted
        // only for collections this time -> want to test only converting is
        // applied for both add and remove
        rep.add(field, convertedValues);
        assertTrue(asCollection(rep.get(field)).size() == 3);
        rep.remove(field, convertedValues);
        assertFalse(rep.get(field).hasNext());
        // a final test to ensure, that remove does not only delete all values
        rep.add(field, allValues);
        assertTrue(asCollection(rep.get(field)).size() == 7);
        rep.remove(field, convertedValues);
        assertTrue(asCollection(rep.get(field)).size() == 4);
    }
View Full Code Here

    @Test
    public void testReferences() {
        String field = "urn:the.field:used.for.this.Test";
        Set<String> refs = new HashSet<String>(Arrays.asList("http://www.test.org/test1",
            "urn:test.org:test.1"));
        Representation rep = createRepresentation(null);
        for (String ref : refs) {
            rep.addReference(field, ref);
        }
        Iterator<Reference> refIterator = rep.getReferences(field);
        assertNotNull(refIterator);
        while (refIterator.hasNext()) {
            Reference ref = refIterator.next();
            assertTrue(refs.remove(ref.getReference()));
        }
View Full Code Here

     * @param valueSet
     *            if not <code>null</code> the added values are added to this set
     * @return the initialised representation
     */
    private Representation initNaturalLanguageTest(String field) {
        Representation rep = createRepresentation(null);
        rep.add(field, NL_TEST_string);
        rep.addNaturalText(field, NL_TEST_noLang);
        rep.addNaturalText(field, NL_TEST_en, "en");
        rep.addNaturalText(field, NL_TEST_en2, "en");
        rep.addNaturalText(field, NL_TEST_de, "de");
        rep.addNaturalText(field, NL_TEST_de_AT, "de-AT");
        return rep;
    }
View Full Code Here

    }

    @Test
    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()));
View Full Code Here

    }

    @Test
    public void testGetNaturalTextWithLanguage() {
        String field = "urn:the.field:used.for.this.Test";
        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());
View Full Code Here

    }

    @Test
    public void testGetNaturalTextWithMultipleLanguages() {
        String field = "urn:the.field:used.for.this.Test";
        Representation rep = initNaturalLanguageTest(field);
        // 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") ||
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.