Search in sources :

Example 51 with ContentItem

use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.

the class ContentItemTest method addingAndRetrieving.

@Test
public void addingAndRetrieving() throws IOException {
    ContentItem ci = createContentItem(contentSource);
    assertNotNull(ci);
    assertNotNull(ci.getUri());
    IRI partUri = new IRI("http://foo/");
    Date someObject = new Date();
    ci.addPart(partUri, someObject);
    ci.getMetadata().add(new TripleImpl(ci.getUri(), new IRI("http://example.org/ontology#hasPart"), partUri));
    ci.getMetadata().add(new TripleImpl(partUri, new IRI("http://example.org/ontology#isPartOf"), ci.getUri()));
    assertEquals(someObject, ci.getPart(partUri, Date.class));
    assertEquals(someObject, ci.getPart(1, Date.class));
    assertEquals(partUri, ci.getPartUri(1));
    assertEquals(new IRI(ci.getUri().getUnicodeString() + "_main"), ci.getPartUri(0));
    try {
        ci.getPart(2, Object.class);
        assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
    } catch (NoSuchPartException e) {
    /* expected*/
    }
    try {
        ci.getPart(new IRI("http://foo/nonexisting"), Object.class);
        assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
    } catch (NoSuchPartException e) {
    /* expected*/
    }
    try {
        ci.getPartUri(2);
        assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
    } catch (NoSuchPartException e) {
    /* expected*/
    }
    //finally log the toString
    log.info("toString: {}", ci);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) NoSuchPartException(org.apache.stanbol.enhancer.servicesapi.NoSuchPartException) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Date(java.util.Date) Test(org.junit.Test)

Example 52 with ContentItem

use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.

the class ContentItemTest method addPartWithoutUri.

@Test(expected = IllegalArgumentException.class)
public void addPartWithoutUri() throws IOException {
    ContentItem ci = createContentItem(contentSource);
    ci.addPart(null, new Date());
}
Also used : ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Date(java.util.Date) Test(org.junit.Test)

Example 53 with ContentItem

use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.

the class ContentItemTest method removeMainContentPartByIndex.

@Test(expected = IllegalStateException.class)
public void removeMainContentPartByIndex() throws IOException {
    ContentItem ci = createContentItem(contentSource);
    ci.removePart(0);
}
Also used : ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 54 with ContentItem

use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.

the class ContentItemTest method removeMainContentPartByUri.

@Test(expected = IllegalStateException.class)
public void removeMainContentPartByUri() throws IOException {
    ContentItem ci = createContentItem(contentSource);
    ci.removePart(ci.getPartUri(0));
}
Also used : ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 55 with ContentItem

use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.

the class DereferenceEngineTest method testAsyncDereferencing.

@Test
public void testAsyncDereferencing() throws Exception {
    ContentItem ci = getContentItem("urn:test:testSyncDereferencing");
    Dictionary<String, Object> dict = new Hashtable<String, Object>();
    dict.put(EnhancementEngine.PROPERTY_NAME, "async");
    dict.put(FILTER_CONTENT_LANGUAGES, false);
    dict.put(FILTER_ACCEPT_LANGUAGES, false);
    EntityDereferenceEngine engine = new EntityDereferenceEngine(asyncDereferencer, new DereferenceEngineConfig(dict, null));
    Assert.assertNotEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
    engine.computeEnhancements(ci);
    validateDereferencedEntities(ci.getMetadata(), ENHANCER_ENTITY_REFERENCE);
}
Also used : Hashtable(java.util.Hashtable) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Aggregations

ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)73 Test (org.junit.Test)62 IRI (org.apache.clerezza.commons.rdf.IRI)46 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)18 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)18 HashMap (java.util.HashMap)15 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)15 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)15 StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)13 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)12 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)11 Graph (org.apache.clerezza.commons.rdf.Graph)8 Date (java.util.Date)6 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)6 Hashtable (java.util.Hashtable)5 AnalysedText (org.apache.stanbol.enhancer.nlp.model.AnalysedText)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 MediaType (javax.ws.rs.core.MediaType)3 Triple (org.apache.clerezza.commons.rdf.Triple)3