Package org.apache.stanbol.enhancer.servicesapi

Examples of org.apache.stanbol.enhancer.servicesapi.Blob


        assertFalse(engine.canEnhance(ci) == CANNOT_ENHANCE);
        engine.computeEnhancements(ci);
        Entry<UriRef,Blob> contentPart = ContentItemHelper.getBlob(ci,
            singleton("text/plain"));
        assertNotNull(contentPart);
        Blob plainTextBlob = contentPart.getValue();
        assertNotNull(plainTextBlob);
        assertContentRegexp(plainTextBlob,
            "Test Title",
            "Test Artist",
            "Test Album");
        //validate XHTML results
        contentPart = ContentItemHelper.getBlob(ci,
            singleton("application/xhtml+xml"));
        assertNotNull(contentPart);
        Blob xhtmlBlob = contentPart.getValue();
        assertNotNull(xhtmlBlob);
        //Test AudioTrack metadata
        NonLiteral audioTrack = verifyNonLiteral(ci, new UriRef(NamespaceEnum.media+"hasTrack"));
        //types
        verifyValues(ci, audioTrack, RDF.type,
View Full Code Here


        assertFalse(engine.canEnhance(ci) == CANNOT_ENHANCE);
        engine.computeEnhancements(ci);
        Entry<UriRef,Blob> contentPart = ContentItemHelper.getBlob(ci,
            singleton("text/plain"));
        assertNotNull(contentPart);
        Blob plainTextBlob = contentPart.getValue();
        assertNotNull(plainTextBlob);
        assertContentRegexp(plainTextBlob,
            "The Apache Stanbol Enhancer",
            "The Stanbol enhancer can detect famous cities");
        //validate XHTML results
        contentPart = ContentItemHelper.getBlob(ci,
            singleton("application/xhtml+xml"));
        assertNotNull(contentPart);
        Blob xhtmlBlob = contentPart.getValue();
        assertNotNull(xhtmlBlob);
        assertContentRegexp(xhtmlBlob,
            "<html xmlns=\"http://www.w3.org/1999/xhtml\">",
            "<head>",
            "<meta name=",
View Full Code Here

        assertFalse(engine.canEnhance(ci) == CANNOT_ENHANCE);
        engine.computeEnhancements(ci);
        Entry<UriRef,Blob> contentPart = ContentItemHelper.getBlob(ci,
            singleton("text/plain"));
        assertNotNull(contentPart);
        Blob plainTextBlob = contentPart.getValue();
        assertNotNull(plainTextBlob);
        assertContentRegexp(plainTextBlob,
            "The Apache Stanbol Enhancer",
            "The Stanbol enhancer can detect famous cities");
        //only the original and the plain text
View Full Code Here

    @Override
    public void computeEnhancements(final ContentItem ci) throws EngineException {
        checkRESTfulNlpAnalysisService(); //validate that the service is active
        //get/create the AnalysedText
        final AnalysedText at = NlpEngineHelper.initAnalysedText(this, analysedTextFactory, ci);
        final Blob blob = at.getBlob();
        //send the text to the server
        final String language = getLanguage(this, ci, true);
        final HttpPost request = new HttpPost(analysisServiceUrl);
        request.addHeader(HttpHeaders.CONTENT_LANGUAGE, language);
        request.setEntity(new InputStreamEntity(
            blob.getStream(), blob.getContentLength(),
            ContentType.create(blob.getMimeType(),
                blob.getParameter().get("charset"))));
        //execute the request
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<AnalysedText>() {
                public AnalysedText run() throws ClientProtocolException, IOException {
                    return httpClient.execute(request, new AnalysisResponseHandler(at));
View Full Code Here

            includedContentPartList = new ArrayList<Map.Entry<UriRef,Blob>>();
            Set<String> ignoreContentPartUris = getIgnoredContentURIs(properties);
            nextContentPartEntry:
            for(Entry<UriRef,Blob> entry : getContentParts(ci,Blob.class).entrySet()){
                if(!ignoreContentPartUris.contains(entry.getKey().getUnicodeString())){
                    Blob blob = entry.getValue();
                    MediaType blobMediaType = MediaType.valueOf(blob.getMimeType());
                    for(MediaType included : includeMediaTypes) {
                        if(blobMediaType.isCompatible(included)){
                            includedContentPartList.add(entry);
                            continue nextContentPartEntry;
                        }
View Full Code Here

     */
    @Override
    public void computeEnhancements(final ContentItem ci) throws EngineException {
        //get/create the AnalysedText
        final AnalysedText at = NlpEngineHelper.initAnalysedText(this, analysedTextFactory, ci);
        final Blob blob = at.getBlob();
        //send the text to the server
        final String language = getLanguage(this, ci, true);
        final HttpPost request = new HttpPost(analysisServiceUrl);
        request.addHeader(HttpHeaders.CONTENT_LANGUAGE, language);
        request.setEntity(new InputStreamEntity(
            blob.getStream(), blob.getContentLength(),
            ContentType.create(blob.getMimeType(),
                blob.getParameter().get("charset"))));
        //execute the request
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<AnalysedText>() {
                public AnalysedText run() throws ClientProtocolException, IOException {
                    return httpClient.execute(request, new AnalysisResponseHandler(at));
View Full Code Here

     */
    @Override
    public void computeEnhancements(final ContentItem ci) throws EngineException {
        //get the plain text Blob
        Map.Entry<UriRef,Blob> textBlob = getPlainText(this, ci, false);
        Blob blob = textBlob.getValue();
        //send the text to the server
        final HttpPost request = new HttpPost(serviceUrl);
        request.setEntity(new InputStreamEntity(
            blob.getStream(), blob.getContentLength(),
            ContentType.create(blob.getMimeType(),
                blob.getParameter().get("charset"))));
        //execute the request
        List<LangSuggestion> detected;
        try {
            detected = AccessController.doPrivileged(new PrivilegedExceptionAction<List<LangSuggestion>>() {
                public List<LangSuggestion> run() throws ClientProtocolException, IOException {
View Full Code Here

     * @throws IOException
     */
    @Test
    public void testString() throws IOException{
        String test = "Exámplê";
        Blob blob = new InMemoryBlob(test, null);
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
       
        String value = new String(IOUtils.toByteArray(blob.getStream()),UTF8);
        Assert.assertEquals(test, value);
    }
View Full Code Here

     * @throws IOException
     */
    @Test
    public void testStringWithCharset() throws IOException{
        String test = "Exámplê";
        Blob blob = new InMemoryBlob(test, "text/plain;charset=ISO-8859-4");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
    }
View Full Code Here

     * Tests the default mimeType "application/octet-stream" for binary data.
     * @throws IOException
     */
    @Test
    public void testDefaultBinaryMimeType() throws IOException {
        Blob blob = new InMemoryBlob("dummy".getBytes(UTF8), null);
        Assert.assertEquals("application/octet-stream", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());

        blob = new InMemoryBlob(new ByteArrayInputStream("dummy".getBytes(UTF8)), null);
        Assert.assertEquals("application/octet-stream", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.Blob

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.