Package org.apache.stanbol.enhancer.servicesapi.impl

Examples of org.apache.stanbol.enhancer.servicesapi.impl.StringSource


     * Tests ensuring the IllegalArgumentExceptions if null is parsed as
     * String to
     */
    @Test(expected=IllegalArgumentException.class)
    public void missingString(){
        new StringSource(null);
    }
View Full Code Here


    public void missingString(){
        new StringSource(null);
    }
    @Test(expected=IllegalArgumentException.class)
    public void missingString1(){
        new StringSource(null,MT);
    }
View Full Code Here

    public void missingString1(){
        new StringSource(null,MT);
    }
    @Test(expected=IllegalArgumentException.class)
    public void missingString2(){
        new StringSource(null,UTF8,MT);
    }
View Full Code Here

        assertSame(DATA, source.getData());
    }
   
    @Test
    public void checkStreamFromStringSource() throws IOException {
        ContentSource source = new StringSource(TEST_STRING);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(source.getStream(), out);
        Assert.assertTrue(Arrays.equals(DATA, out.toByteArray()));
        try {
            source.getStream();
            //multiple calls are supported -> is OK
        } catch (RuntimeException e) {
            //multiple calls are not supported -> illegal state
            Assert.assertTrue(e instanceof IllegalStateException);
        }
        //test different encoding
        Charset ISO8859_4 = Charset.forName("ISO-8859-4");
        byte[] iso8859_4_data = TEST_STRING.getBytes(ISO8859_4);
        source = new StringSource(TEST_STRING,ISO8859_4,null);
        out = new ByteArrayOutputStream();
        IOUtils.copy(source.getStream(), out);
        Assert.assertTrue(Arrays.equals(iso8859_4_data, out.toByteArray()));
       
    }
View Full Code Here

        source = new ByteArraySource(DATA,MT_WITH_PARAM,FILE_NAME,HEADERS);
        assertEquals(MT_WITH_PARAM, source.getMediaType());
    }
    @Test
    public void checkMediaTypeForStringSource() throws IOException {
        ContentSource source = new StringSource(TEST_STRING);
        assertEquals(STRING_DEFAULT_MT, source.getMediaType());
        source = new StringSource(TEST_STRING,null);
        assertEquals(STRING_DEFAULT_MT, source.getMediaType());
        source = new StringSource(TEST_STRING,UTF8,null);
        assertEquals(STRING_DEFAULT_MT, source.getMediaType());
        source = new StringSource(TEST_STRING,null,null);
        assertEquals(STRING_DEFAULT_MT, source.getMediaType());
       
        //this can be used to force the system default
        source = new StringSource(TEST_STRING,Charset.defaultCharset(),null);
        Map<String,String> mt = ContentItemHelper.parseMimeType(source.getMediaType());
        assertEquals("text/plain", mt.get(null));
        assertEquals(Charset.defaultCharset().name(), mt.get("charset"));
       
        String OTHER_MT = "text/rtf";
        source = new StringSource(TEST_STRING,OTHER_MT);
        mt = ContentItemHelper.parseMimeType(source.getMediaType());
        assertEquals(OTHER_MT, mt.get(null));
        assertEquals(UTF8.name(), mt.get("charset"));
       
        source = new StringSource(TEST_STRING, null,OTHER_MT);
        mt = ContentItemHelper.parseMimeType(source.getMediaType());
        assertEquals(OTHER_MT, mt.get(null));
        assertEquals(UTF8.name(), mt.get("charset"));
       
        Charset ISO8859_4 = Charset.forName("ISO-8859-4");
        source = new StringSource(TEST_STRING, ISO8859_4,OTHER_MT);
        mt = ContentItemHelper.parseMimeType(source.getMediaType());
        assertEquals(OTHER_MT, mt.get(null));
        assertEquals(ISO8859_4.name(), mt.get("charset"));
    }
View Full Code Here

     * @throws IOException
     */
    private ContentItem initContentItem() throws IOException {
        ContentItem ci = ciFactory.createContentItem(
            new UriRef("urn:iks-project:enhancer:text:content-item:person"),
            new StringSource(CONTEXT));
        //add three text annotations to be consumed by this test
        getTextAnnotation(ci, PERSON, CONTEXT, DBPEDIA_PERSON);
        getTextAnnotation(ci, ORGANISATION, CONTEXT, DBPEDIA_ORGANISATION);
        getTextAnnotation(ci, PLACE, CONTEXT, DBPEDIA_PLACE);
        //add the language
View Full Code Here

  public static void shutdownServices() {
    nerEngine.deactivate(null);
  }

    public static ContentItem wrapAsContentItem(final String text) throws IOException {
        return ciFactory.createContentItem(new StringSource(text));
    }
View Full Code Here

  public static void shutdownServices() {
    sentimentAnalysisEngine.deactivate(null);
  }

  public static ContentItem wrapAsContentItem(final String text) throws IOException {
    return ciFactory.createContentItem(new StringSource(text));
  }
View Full Code Here

  public static void shutdownServices() {
    classificationEngine.deactivate(null);
  }

  public static ContentItem wrapAsContentItem(final String text) throws IOException {
    return ciFactory.createContentItem(new StringSource(text));
  }
View Full Code Here

        engine = null;
    }
   
    @Test
    public void testEngine() throws IOException, EngineException {
        ContentItem ci = ciFactory.createContentItem(new StringSource(text));
        Assert.assertNotNull(ci);
        AnalysedText at = atFactory.createAnalysedText(ci, ci.getBlob());
        Assert.assertNotNull(at);
        ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl("it")));
        Assert.assertEquals("it", EnhancementEngineHelper.getLanguage(ci));
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.impl.StringSource

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.