Modified: stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java?rev=1744328&r1=1744327&r2=1744328&view=diff ============================================================================== --- stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java (original) +++ stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java Tue May 17 22:20:49 2016 @@ -40,16 +40,15 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.clerezza.rdf.core.Graph; +import org.apache.clerezza.commons.rdf.ImmutableGraph; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.BlankNodeOrIRI; +import org.apache.clerezza.commons.rdf.RDFTerm; +import org.apache.clerezza.commons.rdf.Triple; +import org.apache.clerezza.commons.rdf.IRI; +import org.apache.clerezza.commons.rdf.Literal; import org.apache.clerezza.rdf.core.LiteralFactory; -import org.apache.clerezza.rdf.core.MGraph; -import org.apache.clerezza.rdf.core.NonLiteral; -import org.apache.clerezza.rdf.core.PlainLiteral; -import org.apache.clerezza.rdf.core.Resource; -import org.apache.clerezza.rdf.core.Triple; -import org.apache.clerezza.rdf.core.TypedLiteral; -import org.apache.clerezza.rdf.core.UriRef; -import org.apache.stanbol.commons.indexedgraph.IndexedMGraph; +import org.apache.stanbol.commons.indexedgraph.IndexedGraph; import org.apache.stanbol.enhancer.servicesapi.Blob; import org.apache.stanbol.enhancer.servicesapi.Chain; import org.apache.stanbol.enhancer.servicesapi.ChainException; @@ -114,7 +113,7 @@ public class EnhancementPropertyTest { private static class TestContentItem extends ContentItemImpl { protected TestContentItem(String uri, String content) { - super(new UriRef(uri), new TestBlob(content), new IndexedMGraph()); + super(new IRI(uri), new TestBlob(content), new IndexedGraph()); } } @@ -171,7 +170,7 @@ public class EnhancementPropertyTest { } @Override - public Graph getExecutionPlan() throws ChainException { + public ImmutableGraph getExecutionPlan() throws ChainException { return ExecutionPlanHelper.calculateExecutionPlan(name, engines, Collections.<String>emptySet(), Collections.<String>emptySet(), chainProperties); @@ -232,8 +231,8 @@ public class EnhancementPropertyTest { */ protected void initExecutionMetadata(Chain chain) throws ChainException { //init the ExecutionMetadata ... this is normally done by the EnhancementJobManager - MGraph em = ExecutionMetadataHelper.initExecutionMetadataContentPart(contentItem); - Graph ep = chain.getExecutionPlan(); + Graph em = ExecutionMetadataHelper.initExecutionMetadataContentPart(contentItem); + ImmutableGraph ep = chain.getExecutionPlan(); em.addAll(ep); ExecutionMetadataHelper.initExecutionMetadata(em, ep, contentItem.getUri(), chain.getName(), false); @@ -349,8 +348,8 @@ public class EnhancementPropertyTest { Collection<String> derefernceLanguages = Arrays.asList("en","de"); Integer maxSuggestions = Integer.valueOf(5); - UriRef maxSuggestionsProperty = new UriRef(NamespaceEnum.ehp + PROPERTY_MAX_SUGGESTIONS); - UriRef dereferenceLanguagesProperty = new UriRef(NamespaceEnum.ehp + PROPERTY_DEREFERENCE_LANGUAGES); + IRI maxSuggestionsProperty = new IRI(NamespaceEnum.ehp + PROPERTY_MAX_SUGGESTIONS); + IRI dereferenceLanguagesProperty = new IRI(NamespaceEnum.ehp + PROPERTY_DEREFERENCE_LANGUAGES); //set up the map with the enhancement properties we want to set for the //Enhancement Chain @@ -363,25 +362,25 @@ public class EnhancementPropertyTest { enhancementProperties.put(linking.getName(), linkingProperties); //create the ExecutionPlan - Graph ep = ExecutionPlanHelper.calculateExecutionPlan("test", engines, + ImmutableGraph ep = ExecutionPlanHelper.calculateExecutionPlan("test", engines, Collections.<String>emptySet(), Collections.<String>emptySet(), enhancementProperties); //now assert that the enhancement properties where correctly written //first the property we set on the chain level - NonLiteral epNode = ExecutionPlanHelper.getExecutionPlan(ep, "test"); + BlankNodeOrIRI epNode = ExecutionPlanHelper.getExecutionPlan(ep, "test"); assertNotNull(epNode); Iterator<Triple> maxSuggestionValues = ep.filter(epNode, maxSuggestionsProperty, null); assertTrue(maxSuggestionValues.hasNext()); - Resource maxSuggestionValue = maxSuggestionValues.next().getObject(); + RDFTerm maxSuggestionValue = maxSuggestionValues.next().getObject(); assertFalse(maxSuggestionValues.hasNext()); - assertTrue(maxSuggestionValue instanceof TypedLiteral); - assertEquals(maxSuggestions.toString(), ((TypedLiteral)maxSuggestionValue).getLexicalForm()); + assertTrue(maxSuggestionValue instanceof Literal); + assertEquals(maxSuggestions.toString(), ((Literal)maxSuggestionValue).getLexicalForm()); assertEquals(maxSuggestions, LiteralFactory.getInstance().createObject( - Integer.class, (TypedLiteral)maxSuggestionValue)); + Integer.class, (Literal)maxSuggestionValue)); //second the property we set for the linking engine boolean found = false; - for(NonLiteral ee : ExecutionPlanHelper.getExecutionNodes(ep, epNode)){ + for(BlankNodeOrIRI ee : ExecutionPlanHelper.getExecutionNodes(ep, epNode)){ String engineName = ExecutionPlanHelper.getEngine(ep, ee); if(linking.getName().equals(engineName)){ found = true; @@ -389,9 +388,9 @@ public class EnhancementPropertyTest { assertTrue(derefLangValues.hasNext()); int numValues = 0; while(derefLangValues.hasNext()){ - Resource r = derefLangValues.next().getObject(); - assertTrue(r instanceof PlainLiteral); - assertTrue(derefernceLanguages.contains(((PlainLiteral)r).getLexicalForm())); + RDFTerm r = derefLangValues.next().getObject(); + assertTrue(r instanceof Literal); + assertTrue(derefernceLanguages.contains(((Literal)r).getLexicalForm())); numValues++; } assertEquals(derefernceLanguages.size(), numValues);
Modified: stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemFactoryTest.java URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemFactoryTest.java?rev=1744328&r1=1744327&r2=1744328&view=diff ============================================================================== --- stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemFactoryTest.java (original) +++ stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemFactoryTest.java Tue May 17 22:20:49 2016 @@ -26,11 +26,11 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.charset.Charset; -import org.apache.clerezza.rdf.core.MGraph; -import org.apache.clerezza.rdf.core.UriRef; -import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl; -import org.apache.clerezza.rdf.core.impl.SimpleMGraph; -import org.apache.clerezza.rdf.core.impl.TripleImpl; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.IRI; +import org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl; +import org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph; +import org.apache.clerezza.commons.rdf.impl.utils.TripleImpl; import org.apache.commons.io.IOUtils; import org.apache.stanbol.enhancer.servicesapi.Blob; import org.apache.stanbol.enhancer.servicesapi.ContentItem; @@ -80,11 +80,11 @@ public abstract class ContentItemFactory /** * The {@link ContentItem#getUri() ID} used for testing */ - private static UriRef ID = new UriRef("http://www.example.com/content-items#12345"); + private static IRI ID = new IRI("http://www.example.com/content-items#12345"); /** - * Graph used to test of parsed metadata are preserved + * ImmutableGraph used to test of parsed metadata are preserved */ - private static MGraph METADATA = new SimpleMGraph(); + private static Graph METADATA = new SimpleGraph(); static { METADATA.add(new TripleImpl(ID, Properties.RDF_TYPE, Enhancer.CONTENT_ITEM)); METADATA.add(new TripleImpl(ID, Properties.RDFS_LABEL, new PlainLiteralImpl("Test ContentItem"))); @@ -138,11 +138,11 @@ public abstract class ContentItemFactory } @Test(expected=IllegalArgumentException.class) public void missingCiContentSource4() throws IOException{ - contentItemFactory.createContentItem(ID,null,new SimpleMGraph()); + contentItemFactory.createContentItem(ID,null,new SimpleGraph()); } @Test(expected=IllegalArgumentException.class) public void missingCiContentSource5() throws IOException{ - contentItemFactory.createContentItem(PREFIX,null,new SimpleMGraph()); + contentItemFactory.createContentItem(PREFIX,null,new SimpleGraph()); } /* * Set of tests to test that IllegalArgumentExceptions are @@ -155,7 +155,7 @@ public abstract class ContentItemFactory } @Test(expected=IllegalArgumentException.class) public void missingCiContentReference2() throws IOException{ - contentItemFactory.createContentItem(null,new SimpleMGraph()); + contentItemFactory.createContentItem(null,new SimpleGraph()); } /* * Set of tests to test that IllegalArgumentExceptions are @@ -179,7 +179,7 @@ public abstract class ContentItemFactory } @Test(expected=IllegalArgumentException.class) public void missingCiPrefix2() throws IOException{ - contentItemFactory.createContentItem((String)null,TEST_CS,new SimpleMGraph()); + contentItemFactory.createContentItem((String)null,TEST_CS,new SimpleGraph()); } /** * Test that the generated ID starts with the parsed prefix @@ -192,7 +192,7 @@ public abstract class ContentItemFactory assertTrue("The ID of the created ContentItem MUST start with the parsed prefix", ci.getUri().getUnicodeString().startsWith(PREFIX)); - ci = contentItemFactory.createContentItem(PREFIX, TEST_CS,new SimpleMGraph()); + ci = contentItemFactory.createContentItem(PREFIX, TEST_CS,new SimpleGraph()); assertNotNull(ci); assertNotNull(ci.getUri()); assertTrue("The ID of the created ContentItem MUST start with the parsed prefix", @@ -209,7 +209,7 @@ public abstract class ContentItemFactory assertTrue("The ID of the created ContentItem MUST be equals to the parsed ID", ci.getUri().equals(ID)); - ci = contentItemFactory.createContentItem(ID, TEST_CS,new SimpleMGraph()); + ci = contentItemFactory.createContentItem(ID, TEST_CS,new SimpleGraph()); assertNotNull(ci); assertNotNull(ci.getUri()); assertTrue("The ID of the created ContentItem MUST be equals to the parsed ID", @@ -224,10 +224,10 @@ public abstract class ContentItemFactory ContentItem ci = contentItemFactory.createContentItem(TEST_CS); assertNotNull(ci); assertNotNull(ci.getUri()); - ci = contentItemFactory.createContentItem((UriRef)null,TEST_CS); + ci = contentItemFactory.createContentItem((IRI)null,TEST_CS); assertNotNull(ci); assertNotNull(ci.getUri()); - ci = contentItemFactory.createContentItem((UriRef)null,TEST_CS, new SimpleMGraph()); + ci = contentItemFactory.createContentItem((IRI)null,TEST_CS, new SimpleGraph()); assertNotNull(ci); assertNotNull(ci.getUri()); } @@ -242,7 +242,7 @@ public abstract class ContentItemFactory assertNotNull(ci.getUri()); assertEquals(TEST_CR.getReference(),ci.getUri().getUnicodeString()); - contentItemFactory.createContentItem(TEST_CR, new SimpleMGraph()); + contentItemFactory.createContentItem(TEST_CR, new SimpleGraph()); assertNotNull(ci); assertNotNull(ci.getUri()); assertEquals(TEST_CR.getReference(),ci.getUri().getUnicodeString()); Modified: stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemTest.java URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemTest.java?rev=1744328&r1=1744327&r2=1744328&view=diff ============================================================================== --- stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemTest.java (original) +++ stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemTest.java Tue May 17 22:20:49 2016 @@ -24,8 +24,8 @@ import static org.junit.Assert.assertTru import java.io.IOException; import java.util.Date; -import org.apache.clerezza.rdf.core.UriRef; -import org.apache.clerezza.rdf.core.impl.TripleImpl; +import org.apache.clerezza.commons.rdf.IRI; +import org.apache.clerezza.commons.rdf.impl.utils.TripleImpl; import org.apache.stanbol.enhancer.servicesapi.Blob; import org.apache.stanbol.enhancer.servicesapi.ContentItem; import org.apache.stanbol.enhancer.servicesapi.ContentSource; @@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory; public abstract class ContentItemTest { private final Logger log = LoggerFactory.getLogger(ContentItemTest.class); - //private static final UriRef ciUri = new UriRef("http://example.org/"); + //private static final IRI ciUri = new IRI("http://example.org/"); private static final ContentSource contentSource = new StringSource("This is a Test!"); /** * Used to create ContentItems used by this Test. Each call MUST return a @@ -60,21 +60,21 @@ public abstract class ContentItemTest { ContentItem ci = createContentItem(contentSource); assertNotNull(ci); assertNotNull(ci.getUri()); - UriRef partUri = new UriRef("http://foo/"); + IRI partUri = new IRI("http://foo/"); Date someObject = new Date(); ci.addPart(partUri, someObject); - ci.getMetadata().add(new TripleImpl(ci.getUri(), new UriRef("http://example.org/ontology#hasPart"), partUri)); - ci.getMetadata().add(new TripleImpl(partUri, new UriRef("http://example.org/ontology#isPartOf"),ci.getUri())); + 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 UriRef(ci.getUri().getUnicodeString()+"_main"), ci.getPartUri(0)); + 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 UriRef("http://foo/nonexisting"), Object.class); + ci.getPart(new IRI("http://foo/nonexisting"), Object.class); assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false); } catch (NoSuchPartException e) {/* expected*/} try { @@ -92,7 +92,7 @@ public abstract class ContentItemTest { @Test(expected=IllegalArgumentException.class) public void addPartWithoutPartContent() throws IOException{ ContentItem ci = createContentItem(contentSource); - ci.addPart(new UriRef("http://foo/"), null); + ci.addPart(new IRI("http://foo/"), null); } /** * The ContentItem MUST NOT allow to replace the main content part (the @@ -101,7 +101,7 @@ public abstract class ContentItemTest { @Test(expected=IllegalArgumentException.class) public void replaceMainPart() throws IOException{ ContentItem ci = createContentItem(contentSource); - UriRef mainPart = ci.getPartUri(0); + IRI mainPart = ci.getPartUri(0); ci.addPart(mainPart, new Date()); } @Test(expected=IllegalArgumentException.class) @@ -127,7 +127,7 @@ public abstract class ContentItemTest { @Test(expected=NoSuchPartException.class) public void removeNonExistentPartByUri() throws IOException { ContentItem ci = createContentItem(contentSource); - ci.removePart(new UriRef("urn:does.not.exist:and.can.not.be.removed")); + ci.removePart(new IRI("urn:does.not.exist:and.can.not.be.removed")); } @Test(expected=NoSuchPartException.class) public void removeNonExistentPartByIndex() throws IOException { @@ -137,7 +137,7 @@ public abstract class ContentItemTest { @Test public void removeRemoveByUri() throws IOException { ContentItem ci = createContentItem(contentSource); - UriRef uri = new UriRef("urn:content.part:remove.test"); + IRI uri = new IRI("urn:content.part:remove.test"); ci.addPart(uri, new Date()); try { ci.getPart(uri, Date.class); @@ -157,12 +157,12 @@ public abstract class ContentItemTest { @Test public void removeRemoveByIndex() throws IOException { ContentItem ci = createContentItem(contentSource); - UriRef uri = new UriRef("urn:content.part:remove.test"); + IRI uri = new IRI("urn:content.part:remove.test"); ci.addPart(uri, new Date()); int index = -1; try { for(int i=0; index < 0; i++){ - UriRef partUri = ci.getPartUri(i); + IRI partUri = ci.getPartUri(i); if(partUri.equals(uri)){ index = i; } Modified: stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/helper/EnhancementStructureHelper.java URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/helper/EnhancementStructureHelper.java?rev=1744328&r1=1744327&r2=1744328&view=diff ============================================================================== --- stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/helper/EnhancementStructureHelper.java (original) +++ stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/helper/EnhancementStructureHelper.java Tue May 17 22:20:49 2016 @@ -47,16 +47,14 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.apache.clerezza.rdf.core.Literal; +import org.apache.clerezza.commons.rdf.Literal; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.BlankNodeOrIRI; +import org.apache.clerezza.commons.rdf.RDFTerm; +import org.apache.clerezza.commons.rdf.Triple; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.IRI; import org.apache.clerezza.rdf.core.LiteralFactory; -import org.apache.clerezza.rdf.core.MGraph; -import org.apache.clerezza.rdf.core.NonLiteral; -import org.apache.clerezza.rdf.core.PlainLiteral; -import org.apache.clerezza.rdf.core.Resource; -import org.apache.clerezza.rdf.core.Triple; -import org.apache.clerezza.rdf.core.TripleCollection; -import org.apache.clerezza.rdf.core.TypedLiteral; -import org.apache.clerezza.rdf.core.UriRef; import org.apache.clerezza.rdf.ontologies.DCTERMS; import org.apache.clerezza.rdf.ontologies.XSD; import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine; @@ -86,7 +84,7 @@ public final class EnhancementStructureH * {@link Class#getName()} as value. * @return the number of found TextAnnotations */ - public static int validateAllTextAnnotations(TripleCollection enhancements, String content, Map<UriRef,Resource> expectedValues) { + public static int validateAllTextAnnotations(Graph enhancements, String content, Map<IRI,RDFTerm> expectedValues) { return validateAllTextAnnotations(enhancements,content,expectedValues,false); } /** @@ -107,7 +105,7 @@ public final class EnhancementStructureH * @return the number of found TextAnnotations */ @SuppressWarnings("unchecked") - public static int validateAllTextAnnotations(TripleCollection enhancements, String content, Map<UriRef,Resource> expectedValues, boolean validatePrefixSuffix) { + public static int validateAllTextAnnotations(Graph enhancements, String content, Map<IRI,RDFTerm> expectedValues, boolean validatePrefixSuffix) { expectedValues = expectedValues == null ? Collections.EMPTY_MAP : expectedValues; Iterator<Triple> textAnnotationIterator = enhancements.filter(null, RDF_TYPE, ENHANCER_TEXTANNOTATION); @@ -116,7 +114,7 @@ public final class EnhancementStructureH // -> this might be used to test that there are no TextAnnotations int textAnnotationCount = 0; while (textAnnotationIterator.hasNext()) { - UriRef textAnnotation = (UriRef) textAnnotationIterator.next().getSubject(); + IRI textAnnotation = (IRI) textAnnotationIterator.next().getSubject(); // test if selected Text is added validateTextAnnotation(enhancements, textAnnotation,content,expectedValues, validatePrefixSuffix); textAnnotationCount++; @@ -127,7 +125,7 @@ public final class EnhancementStructureH /** * Validates the parsed TextAnnotation with a fise:selected-text. This * method also validates rules defined by fise:Enhancement by calling - * {@link #validateEnhancement(TripleCollection, UriRef, Map)}<p> + * {@link #validateEnhancement(Graph, IRI, Map)}<p> * NOTE: this method MUST NOT be used to validate fise:TextAnnotations that * do NOT select a part of the text - meaning TextAnnotations about the * whole parsed content. @@ -136,7 +134,7 @@ public final class EnhancementStructureH * @param content the enhanced content * @param expectedValues expected values (properties for the values are used as keys) */ - public static void validateTextAnnotation(TripleCollection enhancements, UriRef textAnnotation, String content, Map<UriRef,Resource> expectedValues) { + public static void validateTextAnnotation(Graph enhancements, IRI textAnnotation, String content, Map<IRI,RDFTerm> expectedValues) { validateTextAnnotation(enhancements,textAnnotation,content,expectedValues,false); } /** @@ -152,7 +150,7 @@ public final class EnhancementStructureH * @param validatePrefixSuffix enforce the presence of fise:selection-prefix and * fise:selection-suffix if fise:start and fise:end are set. */ - public static void validateTextAnnotation(TripleCollection enhancements, UriRef textAnnotation, String content, Map<UriRef,Resource> expectedValues, boolean validatePrefixSuffix) { + public static void validateTextAnnotation(Graph enhancements, IRI textAnnotation, String content, Map<IRI,RDFTerm> expectedValues, boolean validatePrefixSuffix) { //validate the rdf:type Iterator<Triple> rdfTypeIterator = enhancements.filter(textAnnotation, RDF_TYPE, ENHANCER_TEXTANNOTATION); assertTrue("Parsed Enhancement "+textAnnotation +" is missing the fise:TextAnnotation type ", @@ -160,12 +158,12 @@ public final class EnhancementStructureH Iterator<Triple> selectedTextIterator = enhancements.filter(textAnnotation, ENHANCER_SELECTED_TEXT, null); // check if the selected text is added (or not) - Resource selectedTextResource; + RDFTerm selectedTextResource; if(selectedTextIterator.hasNext()){ // test if the selected text is part of the TEXT_TO_TEST selectedTextResource = selectedTextIterator.next().getObject(); assertTrue("fise:selected-text MUST BE of type PlainLiteral (uri: "+textAnnotation+")", - selectedTextResource instanceof PlainLiteral); + selectedTextResource instanceof Literal); Literal selectedText = (Literal)selectedTextResource; assertTrue("The parsed content MUST contain the fise:selected-text value '" +selectedText.getLexicalForm()+"' (uri: "+textAnnotation+")!",content.contains(selectedText.getLexicalForm())); @@ -174,7 +172,7 @@ public final class EnhancementStructureH selectedTextResource = null; //no selected text } //check against an expected value - Resource expectedSelectedText = expectedValues.get(ENHANCER_SELECTED_TEXT); + RDFTerm expectedSelectedText = expectedValues.get(ENHANCER_SELECTED_TEXT); if(expectedSelectedText != null){ assertEquals("The fise:selected-text is not the expected value "+expectedSelectedText+" (uri: "+textAnnotation+")!", expectedSelectedText, selectedTextResource); @@ -184,12 +182,12 @@ public final class EnhancementStructureH if(selectedTextResource != null){ Assert.assertFalse("If fise:selected-text is present fise:selection-head MUST NOT be present",selectionHeadIterator.hasNext()); } - Resource selectionHeadResource; + RDFTerm selectionHeadResource; if(selectionHeadIterator.hasNext()){ // test if the selected text is part of the TEXT_TO_TEST selectionHeadResource = selectionHeadIterator.next().getObject(); assertTrue("fise:selection-head MUST BE of type PlainLiteral (uri: "+textAnnotation+")", - selectionHeadResource instanceof PlainLiteral); + selectionHeadResource instanceof Literal); Literal selectionHeadText = (Literal)selectionHeadResource; assertTrue("The parsed content MUST contain the fise:selected-head value '" +selectionHeadText.getLexicalForm()+"' (uri: "+textAnnotation+")!",content.contains(selectionHeadText.getLexicalForm())); @@ -202,12 +200,12 @@ public final class EnhancementStructureH if(selectedTextResource != null){ Assert.assertFalse("If fise:selected-text is present fise:selection-tail MUST NOT be present",selectionTailIterator.hasNext()); } - Resource selectionTailResource; + RDFTerm selectionTailResource; if(selectionTailIterator.hasNext()){ // test if the selected text is part of the TEXT_TO_TEST selectionTailResource = selectionTailIterator.next().getObject(); assertTrue("fise:selection-head MUST BE of type PlainLiteral (uri: "+textAnnotation+")", - selectionTailResource instanceof PlainLiteral); + selectionTailResource instanceof Literal); Literal selectionTailText = (Literal)selectionTailResource; assertTrue("The parsed content MUST contain the fise:selected-tail value '" +selectionTailText.getLexicalForm()+"' (uri: "+textAnnotation+")!",content.contains(selectionTailText.getLexicalForm())); @@ -220,7 +218,7 @@ public final class EnhancementStructureH (selectionHeadResource != null && selectionTailResource != null) || (selectionHeadResource == null && selectionTailResource == null)); - Resource selectionContextResource; + RDFTerm selectionContextResource; // test if context is added Iterator<Triple> selectionContextIterator = enhancements.filter(textAnnotation, ENHANCER_SELECTION_CONTEXT, null); @@ -231,7 +229,7 @@ public final class EnhancementStructureH // test if the selected text is part of the TEXT_TO_TEST selectionContextResource = selectionContextIterator.next().getObject(); assertTrue("The fise:selection-context MUST BE of type PlainLiteral (uri: "+textAnnotation+")", - selectionContextResource instanceof PlainLiteral); + selectionContextResource instanceof Literal); //check that the content contains the context assertTrue("The fise:selection-context MUST BE contained in the Content | context= "+ selectionContextResource, content.contains(((Literal)selectionContextResource).getLexicalForm())); @@ -255,7 +253,7 @@ public final class EnhancementStructureH assertNull("If no fise:selection-context is present also fise:selected-text MUST BE NOT present!", selectedTextResource); selectionContextResource = null; } - Resource expectedSelectionContext = expectedValues.get(ENHANCER_SELECTION_CONTEXT); + RDFTerm expectedSelectionContext = expectedValues.get(ENHANCER_SELECTION_CONTEXT); if(expectedSelectionContext != null){ assertEquals("The value of fise:selection-context has not the expected value "+expectedSelectionContext, expectedSelectionContext, selectionContextResource); @@ -266,19 +264,19 @@ public final class EnhancementStructureH Iterator<Triple> endPosIterator = enhancements.filter(textAnnotation, ENHANCER_END, null); //start end is optional, but if start is present, that also end needs to be set - TypedLiteral startPosLiteral; - TypedLiteral endPosLiteral; + Literal startPosLiteral; + Literal endPosLiteral; if(startPosIterator.hasNext()){ //NOTE: TextAnnotations might be use to select whole sections of a text // (e.g. see STANBOL-617) in those cases adding the text of the // whole section is not feasible. //assertNotNull("If fise:start is present the fise:selection-context MUST also be present (uri: "+textAnnotation+")!", // selectionContextResource); - Resource resource = startPosIterator.next().getObject(); + RDFTerm resource = startPosIterator.next().getObject(); //only a single start position is supported assertFalse("fise:start MUST HAVE only a single value (uri: "+textAnnotation+")!",startPosIterator.hasNext()); - assertTrue("fise:start MUST be a typed Literal (uri: "+textAnnotation+")!",resource instanceof TypedLiteral); - startPosLiteral = (TypedLiteral) resource; + assertTrue("fise:start MUST be a typed Literal (uri: "+textAnnotation+")!",resource instanceof Literal); + startPosLiteral = (Literal) resource; assertEquals("fise:start MUST use xsd:int as data type (uri: "+textAnnotation+")",XSD.int_, startPosLiteral.getDataType()); resource = null; Integer start = LiteralFactory.getInstance().createObject(Integer.class, startPosLiteral); @@ -289,8 +287,8 @@ public final class EnhancementStructureH resource = endPosIterator.next().getObject(); //only a single end position is supported assertFalse("fise:end MUST HAVE only a single value (uri: "+textAnnotation+")!",endPosIterator.hasNext()); - assertTrue("fise:end values MUST BE TypedLiterals (uri: "+textAnnotation+")",resource instanceof TypedLiteral); - endPosLiteral = (TypedLiteral) resource; + assertTrue("fise:end values MUST BE TypedLiterals (uri: "+textAnnotation+")",resource instanceof Literal); + endPosLiteral = (Literal) resource; assertEquals("fise:end MUST use xsd:int as data type (uri: "+textAnnotation+")",XSD.int_, endPosLiteral.getDataType()); resource = null; Integer end = LiteralFactory.getInstance().createObject(Integer.class, endPosLiteral); @@ -309,12 +307,12 @@ public final class EnhancementStructureH startPosLiteral = null; endPosLiteral = null; } - Resource expectedStartPos = expectedValues.get(ENHANCER_START); + RDFTerm expectedStartPos = expectedValues.get(ENHANCER_START); if(expectedStartPos != null){ assertEquals("The fise:start value is not the expected "+expectedStartPos, expectedStartPos, startPosLiteral); } - Resource expectedEndPos = expectedValues.get(ENHANCER_END); + RDFTerm expectedEndPos = expectedValues.get(ENHANCER_END); if(expectedEndPos != null){ assertEquals("The fise:end value is not the expected "+expectedEndPos, expectedEndPos, endPosLiteral); @@ -331,9 +329,9 @@ public final class EnhancementStructureH !validatePrefixSuffix); //to support old and new fise:TextAnnotation model // test if the selected text is part of the TEXT_TO_TEST if(selectionPrefixIterator.hasNext()){ - Resource selectionPrefixResource = selectionPrefixIterator.next().getObject(); + RDFTerm selectionPrefixResource = selectionPrefixIterator.next().getObject(); assertTrue("fise:selection-prefix MUST BE of type PlainLiteral (uri: "+textAnnotation+")", - selectionPrefixResource instanceof PlainLiteral); + selectionPrefixResource instanceof Literal); prefixLiteral = (Literal)selectionPrefixResource; assertTrue("The parsed content MUST contain the fise:selection-prefix value '" +prefixLiteral.getLexicalForm()+"' (uri: "+textAnnotation+")!",content.contains(prefixLiteral.getLexicalForm())); @@ -355,9 +353,9 @@ public final class EnhancementStructureH !validatePrefixSuffix); //to support old and new fise:TextAnnotation model if(selectionSuffixIterator.hasNext()){ // test if the selected text is part of the TEXT_TO_TEST - Resource selectionSuffixResource = selectionSuffixIterator.next().getObject(); + RDFTerm selectionSuffixResource = selectionSuffixIterator.next().getObject(); assertTrue("fise:selection-suffix MUST BE of type PlainLiteral (uri: "+textAnnotation+")", - selectionSuffixResource instanceof PlainLiteral); + selectionSuffixResource instanceof Literal); suffixLiteral = (Literal)selectionSuffixResource; assertTrue("The parsed content MUST contain the fise:selection-suffix value '" +suffixLiteral.getLexicalForm()+"' (uri: "+textAnnotation+")!",content.contains(suffixLiteral.getLexicalForm())); @@ -405,15 +403,15 @@ public final class EnhancementStructureH * Validates the correctness of fise:TextAnnotations that annotate the language * of the text as defined by * <a href="https://issues.apache.org/jira/browse/STANBOL-613">STANBOL-613</a><p> - * Called by {@link #validateTextAnnotation(TripleCollection, UriRef, String, Map)} + * Called by {@link #validateTextAnnotation(Graph, IRI, String, Map)} * @param enhancements * @param textAnnotation */ - private static void validateLanguageAnnotations(TripleCollection enhancements, UriRef textAnnotation) { + private static void validateLanguageAnnotations(Graph enhancements, IRI textAnnotation) { Iterator<Triple> dcLanguageIterator = enhancements.filter(textAnnotation, DC_LANGUAGE, null); if(dcLanguageIterator.hasNext()){ //a language annotation - Resource dcLanguageResource = dcLanguageIterator.next().getObject(); - assertTrue("The dc:language value MUST BE a PlainLiteral", dcLanguageResource instanceof PlainLiteral); + RDFTerm dcLanguageResource = dcLanguageIterator.next().getObject(); + assertTrue("The dc:language value MUST BE a PlainLiteral", dcLanguageResource instanceof Literal); assertTrue("The dc:language value '"+dcLanguageResource+"'MUST BE at least two chars long", ((Literal)dcLanguageResource).getLexicalForm().length() >=2); assertFalse("TextAnnotations with the dc:language property MUST only have a single dc:language value (uri " @@ -428,7 +426,7 @@ public final class EnhancementStructureH +textAnnotation+")",dcTypeIterator.hasNext()); //assert that the created TextAnnotation is correctly returned by the //EnhancementEngineHelper methods - List<NonLiteral> languageAnnotation = EnhancementEngineHelper.getLanguageAnnotations(enhancements); + List<BlankNodeOrIRI> languageAnnotation = EnhancementEngineHelper.getLanguageAnnotations(enhancements); assertTrue("Language annotation "+textAnnotation+" was not returned by " +"EnhancementEngineHelper.getLanguageAnnotations(..)!",languageAnnotation.contains(textAnnotation)); } else { //no language annotation @@ -446,16 +444,16 @@ public final class EnhancementStructureH * dbp-ont:Organisation and dbp-ont:Place do have a * fise:selected-text value (this implicitly also checks that * fise:selection-context, fise:start and fise:end are defined!<p> - * Called by {@link #validateTextAnnotation(TripleCollection, UriRef, String, Map)} + * Called by {@link #validateTextAnnotation(Graph, IRI, String, Map)} * @param enhancements * @param textAnnotation * @param selectedTextResource the fise:selected-text value */ - private static void validateNERAnnotations(TripleCollection enhancements, UriRef textAnnotation, Resource selectedTextResource) { + private static void validateNERAnnotations(Graph enhancements, IRI textAnnotation, RDFTerm selectedTextResource) { Iterator<Triple> dcTypeIterator = enhancements.filter(textAnnotation, DC_TYPE, null); boolean isNERAnnotation = false; while(dcTypeIterator.hasNext() && !isNERAnnotation){ - Resource dcTypeValue = dcTypeIterator.next().getObject(); + RDFTerm dcTypeValue = dcTypeIterator.next().getObject(); isNERAnnotation = DBPEDIA_PERSON.equals(dcTypeValue) || DBPEDIA_ORGANISATION.equals(dcTypeValue) || DBPEDIA_PLACE.equals(dcTypeValue); @@ -477,13 +475,13 @@ public final class EnhancementStructureH * @return the number of found and validated EntityAnnotations. */ @SuppressWarnings("unchecked") - public static int validateAllEntityAnnotations(TripleCollection enhancements,Map<UriRef,Resource> expectedValues) { + public static int validateAllEntityAnnotations(Graph enhancements,Map<IRI,RDFTerm> expectedValues) { expectedValues = expectedValues == null ? Collections.EMPTY_MAP : expectedValues; Iterator<Triple> entityAnnotationIterator = enhancements.filter(null, RDF_TYPE, ENHANCER_ENTITYANNOTATION); int entityAnnotationCount = 0; while (entityAnnotationIterator.hasNext()) { - UriRef entityAnnotation = (UriRef) entityAnnotationIterator.next().getSubject(); + IRI entityAnnotation = (IRI) entityAnnotationIterator.next().getSubject(); // test if selected Text is added validateEntityAnnotation(enhancements, entityAnnotation, expectedValues); @@ -495,12 +493,12 @@ public final class EnhancementStructureH /** * Checks if a fise:EntityAnnotation is valid. NOTE that this also validates * all fise:Enhancement related requirements by calling - * {@link #validateEnhancement(TripleCollection, UriRef, Map)} + * {@link #validateEnhancement(Graph, IRI, Map)} * @param enhancements the enhancements graph * @param entityAnnotation the entity annotation to validate * @param expectedValues expected values (properties for the values are used as keys) */ - public static void validateEntityAnnotation(TripleCollection enhancements, UriRef entityAnnotation,Map<UriRef,Resource> expectedValues) { + public static void validateEntityAnnotation(Graph enhancements, IRI entityAnnotation,Map<IRI,RDFTerm> expectedValues) { Iterator<Triple> relationToTextAnnotationIterator = enhancements.filter( entityAnnotation, DC_RELATION, null); // check if the relation to the text annotation is set @@ -509,7 +507,7 @@ public final class EnhancementStructureH // test if the referred annotations are text annotations or // the referenced annotations is a fise:EntityAnnotation AND also a // dc:requires link is defined (STANBOL-766) - UriRef referredTextAnnotation = (UriRef) relationToTextAnnotationIterator.next().getObject(); + IRI referredTextAnnotation = (IRI) relationToTextAnnotationIterator.next().getObject(); assertTrue("fise:EntityAnnotations MUST BE dc:related to a fise:TextAnnotation OR dc:requires and dc:related to the same fise:EntityAnnotation", enhancements.filter(referredTextAnnotation, RDF_TYPE, ENHANCER_TEXTANNOTATION).hasNext() || ( @@ -523,11 +521,11 @@ public final class EnhancementStructureH ENHANCER_ENTITY_REFERENCE, null); assertTrue("fise:entity-reference MUST BE present! (EntityAnnotation: '" +entityAnnotation+"')'",entityReferenceIterator.hasNext()); - Resource expectedReferencedEntity = expectedValues.get(ENHANCER_ENTITY_REFERENCE); + RDFTerm expectedReferencedEntity = expectedValues.get(ENHANCER_ENTITY_REFERENCE); while(entityReferenceIterator.hasNext()){ //check possible multiple references - Resource entityReferenceResource = entityReferenceIterator.next().getObject(); + RDFTerm entityReferenceResource = entityReferenceIterator.next().getObject(); // test if the reference is an URI - assertTrue("fise:entity-reference value MUST BE of URIs",entityReferenceResource instanceof UriRef); + assertTrue("fise:entity-reference value MUST BE of URIs",entityReferenceResource instanceof IRI); if(expectedReferencedEntity != null && expectedReferencedEntity.equals(entityReferenceResource)){ expectedReferencedEntity = null; //found } @@ -538,11 +536,11 @@ public final class EnhancementStructureH //test if the entity label is set Iterator<Triple> entityLabelIterator = enhancements.filter(entityAnnotation, ENHANCER_ENTITY_LABEL, null); assertTrue(entityLabelIterator.hasNext()); - Resource expectedEntityLabel = expectedValues.get(ENHANCER_ENTITY_LABEL); + RDFTerm expectedEntityLabel = expectedValues.get(ENHANCER_ENTITY_LABEL); while(entityLabelIterator.hasNext()){ - Resource entityLabelResource = entityLabelIterator.next().getObject(); + RDFTerm entityLabelResource = entityLabelIterator.next().getObject(); assertTrue("fise:entity-label values MUST BE PlainLiterals (EntityAnnotation: "+entityAnnotation+")!", - entityLabelResource instanceof PlainLiteral); + entityLabelResource instanceof Literal); if(expectedEntityLabel != null && expectedEntityLabel.equals(entityLabelResource)){ expectedEntityLabel = null; } @@ -552,10 +550,10 @@ public final class EnhancementStructureH //test the optional entity types Iterator<Triple> entityTypeIterator = enhancements.filter(entityAnnotation, Properties.ENHANCER_ENTITY_TYPE, null); - Resource expectedEntityType = expectedValues.get(Properties.ENHANCER_ENTITY_TYPE); + RDFTerm expectedEntityType = expectedValues.get(Properties.ENHANCER_ENTITY_TYPE); if(entityTypeIterator.hasNext()){ - Resource entityTypeResource = entityTypeIterator.next().getObject(); - assertTrue("fise:entity-type values MUST BE URIs",entityTypeResource instanceof UriRef); + RDFTerm entityTypeResource = entityTypeIterator.next().getObject(); + assertTrue("fise:entity-type values MUST BE URIs",entityTypeResource instanceof IRI); if(expectedEntityType != null && expectedEntityType.equals(entityTypeResource)){ expectedEntityType = null; //found } @@ -567,13 +565,13 @@ public final class EnhancementStructureH } /** * Validates all fise:Enhancement related properties and values. NOTE that - * this method is called by {@link #validateEntityAnnotation(TripleCollection, UriRef, Map)} - * and {@link #validateTextAnnotation(TripleCollection, UriRef, String)}. + * this method is called by {@link #validateEntityAnnotation(Graph, IRI, Map)} + * and {@link #validateTextAnnotation(Graph, IRI, String)}. * @param enhancements the enhancements graph * @param enhancement the fise:Enhancement to validate * @param expectedValues expected values (properties for the values are used as keys) */ - public static void validateEnhancement(TripleCollection enhancements, UriRef enhancement, Map<UriRef,Resource> expectedValues){ + public static void validateEnhancement(Graph enhancements, IRI enhancement, Map<IRI,RDFTerm> expectedValues){ //validate the rdf:type Iterator<Triple> rdfTypeIterator = enhancements.filter(enhancement, RDF_TYPE, ENHANCER_ENHANCEMENT); assertTrue("Parsed Enhancement "+enhancement +" is missing the fise:Enhancement type ", @@ -581,28 +579,28 @@ public final class EnhancementStructureH //validate the creator Iterator<Triple> creatorIterator = enhancements.filter(enhancement, Properties.DC_CREATOR, null); assertTrue("Enhancements MUST HAVE a creator",creatorIterator.hasNext()); - Resource creatorResource = creatorIterator.next().getObject(); + RDFTerm creatorResource = creatorIterator.next().getObject(); assertTrue("Creator MUST BE an TypedLiteral (found '"+creatorResource.getClass().getSimpleName()+"')!", - creatorResource instanceof TypedLiteral || creatorResource instanceof UriRef); - if(creatorResource instanceof TypedLiteral){ + creatorResource instanceof Literal || creatorResource instanceof IRI); + if(creatorResource instanceof Literal){ assertEquals("The dc:creator value MUST be of dataType xsd:string", - XSD.string,((TypedLiteral)creatorResource).getDataType()); + XSD.string,((Literal)creatorResource).getDataType()); } - Resource expectedCreator = expectedValues.get(Properties.DC_CREATOR); + RDFTerm expectedCreator = expectedValues.get(Properties.DC_CREATOR); if(expectedCreator != null){ assertEquals("Creator is not the expected value!",expectedCreator, creatorResource); } assertFalse("only a single creater MUST BE present for an Enhancement", creatorIterator.hasNext()); //validate the optional contributor - Resource expectedContributor = expectedValues.get(DCTERMS.contributor); + RDFTerm expectedContributor = expectedValues.get(DCTERMS.contributor); Iterator<Triple> contributorIterator = enhancements.filter(enhancement, DCTERMS.contributor, null); while(contributorIterator.hasNext()){ - Resource contributorResource = contributorIterator.next().getObject(); - assertTrue("Creator MUST BE an TypedLiteral or an UriRef (found '"+contributorResource.getClass().getSimpleName()+"')!", - contributorResource instanceof TypedLiteral || contributorResource instanceof UriRef); - if(contributorResource instanceof TypedLiteral){ + RDFTerm contributorResource = contributorIterator.next().getObject(); + assertTrue("Creator MUST BE an TypedLiteral or an IRI (found '"+contributorResource.getClass().getSimpleName()+"')!", + contributorResource instanceof Literal || contributorResource instanceof IRI); + if(contributorResource instanceof Literal){ assertEquals("The dc:contributor value MUST be of dataType xsd:string", - XSD.string,((TypedLiteral)contributorResource).getDataType()); + XSD.string,((Literal)contributorResource).getDataType()); } if(expectedContributor != null && expectedContributor.equals(expectedContributor)){ expectedContributor = null; //found @@ -613,11 +611,11 @@ public final class EnhancementStructureH //validate creation date Iterator<Triple> createdIterator = enhancements.filter(enhancement, Properties.DC_CREATED, null); assertTrue("The creation date MUST BE present for an Enhancement", createdIterator.hasNext()); - Resource createdResource = createdIterator.next().getObject(); - assertTrue("Creation date MUST be a typed Literal", createdResource instanceof TypedLiteral); + RDFTerm createdResource = createdIterator.next().getObject(); + assertTrue("Creation date MUST be a typed Literal", createdResource instanceof Literal); assertTrue("Creation date MUST have the dataTyoe xsd:dateTime", - XSD.dateTime.equals(((TypedLiteral)createdResource).getDataType())); - Date creationDate = LiteralFactory.getInstance().createObject(Date.class, (TypedLiteral)createdResource); + XSD.dateTime.equals(((Literal)createdResource).getDataType())); + Date creationDate = LiteralFactory.getInstance().createObject(Date.class, (Literal)createdResource); assertNotNull("Unable to convert "+createdResource+" to a Java Date object",creationDate); Date now = new Date(); assertTrue("CreationDate MUST NOT be in the Future",now.after(creationDate) || now.equals(creationDate)); @@ -625,21 +623,21 @@ public final class EnhancementStructureH //validate optional modification date if present Iterator<Triple> modDateIterator = enhancements.filter(enhancement, DCTERMS.modified, null); while(modDateIterator.hasNext()){ - Resource modDateResurce = modDateIterator.next().getObject(); - assertTrue("Creation date MUST be a typed Literal", modDateResurce instanceof TypedLiteral); + RDFTerm modDateResurce = modDateIterator.next().getObject(); + assertTrue("Creation date MUST be a typed Literal", modDateResurce instanceof Literal); assertTrue("Creation date MUST have the dataTyoe xsd:dateTime", - XSD.dateTime.equals(((TypedLiteral)modDateResurce).getDataType())); - Date modDate = LiteralFactory.getInstance().createObject(Date.class, (TypedLiteral)modDateResurce); + XSD.dateTime.equals(((Literal)modDateResurce).getDataType())); + Date modDate = LiteralFactory.getInstance().createObject(Date.class, (Literal)modDateResurce); assertNotNull("Unable to convert "+modDateResurce+" to a Java Date object",modDate); assertTrue("CreationDate MUST NOT be in the Future",new Date().after(modDate)); } //validate the fise:extracted-from Iterator<Triple> extractedIterator = enhancements.filter(enhancement, Properties.ENHANCER_EXTRACTED_FROM, null); assertTrue("The fise:extracted-from property MUST BE present for an Enhancement", extractedIterator.hasNext()); - Resource extractedResource = extractedIterator.next().getObject(); - assertTrue("Creator MUST BE an UriRef (found '"+extractedResource.getClass().getSimpleName()+"')!", - extractedResource instanceof UriRef); - Resource expectedExtractedFrom = expectedValues.get(Properties.ENHANCER_EXTRACTED_FROM); + RDFTerm extractedResource = extractedIterator.next().getObject(); + assertTrue("Creator MUST BE an IRI (found '"+extractedResource.getClass().getSimpleName()+"')!", + extractedResource instanceof IRI); + RDFTerm expectedExtractedFrom = expectedValues.get(Properties.ENHANCER_EXTRACTED_FROM); if(expectedExtractedFrom != null){ assertEquals("fise:extracted-from has not the expected value!",expectedExtractedFrom, extractedResource); } @@ -647,27 +645,27 @@ public final class EnhancementStructureH //validate that all dc:requires and dc:relation link to resources of type fise:Enhancement Iterator<Triple> relatedIterator = enhancements.filter(enhancement, Properties.DC_RELATION, null); while(relatedIterator.hasNext()){ - Resource relatedResource = relatedIterator.next().getObject(); - assertTrue("dc:relation values MUST BE URIs", relatedResource instanceof UriRef); - Iterator<Triple> relatedTypes = enhancements.filter((UriRef)relatedResource, RDF_TYPE, TechnicalClasses.ENHANCER_ENHANCEMENT); + RDFTerm relatedResource = relatedIterator.next().getObject(); + assertTrue("dc:relation values MUST BE URIs", relatedResource instanceof IRI); + Iterator<Triple> relatedTypes = enhancements.filter((IRI)relatedResource, RDF_TYPE, TechnicalClasses.ENHANCER_ENHANCEMENT); assertTrue("dc:relation Resources MUST BE of rdf:type fise:Enhancement",relatedTypes.hasNext()); } Iterator<Triple> requiresIterator = enhancements.filter(enhancement, Properties.DC_REQUIRES, null); while(requiresIterator.hasNext()){ - Resource requiredResource = requiresIterator.next().getObject(); - assertTrue("dc:requires values MUST BE URIs", requiredResource instanceof UriRef); - Iterator<Triple> relatedTypes = enhancements.filter((UriRef)requiredResource, RDF_TYPE, TechnicalClasses.ENHANCER_ENHANCEMENT); + RDFTerm requiredResource = requiresIterator.next().getObject(); + assertTrue("dc:requires values MUST BE URIs", requiredResource instanceof IRI); + Iterator<Triple> relatedTypes = enhancements.filter((IRI)requiredResource, RDF_TYPE, TechnicalClasses.ENHANCER_ENHANCEMENT); assertTrue("dc:requires Resources MUST BE of rdf:type fise:Enhancement",relatedTypes.hasNext()); } //validate that fise:confidence has [0..1] values and are of type xsd:float Iterator<Triple> confidenceIterator = enhancements.filter(enhancement,Properties.ENHANCER_CONFIDENCE,null); boolean confidenceRequired = expectedValues.containsKey(Properties.ENHANCER_CONFIDENCE); if(confidenceIterator.hasNext()){ //confidence is optional - Resource confidenceResource = confidenceIterator.next().getObject(); - assertTrue("fise:confidence value MUST BE a TypedLiteral", confidenceResource instanceof TypedLiteral); + RDFTerm confidenceResource = confidenceIterator.next().getObject(); + assertTrue("fise:confidence value MUST BE a TypedLiteral", confidenceResource instanceof Literal); assertTrue("fise:confidence MUST BE xsd:double", - XSD.double_.equals(((TypedLiteral)confidenceResource).getDataType())); - Double confidence = LiteralFactory.getInstance().createObject(Double.class, (TypedLiteral)confidenceResource); + XSD.double_.equals(((Literal)confidenceResource).getDataType())); + Double confidence = LiteralFactory.getInstance().createObject(Double.class, (Literal)confidenceResource); assertNotNull("Unable to convert TypedLiteral '"+confidenceResource+"' to a Java Double value",confidence); assertFalse("fise:confidence MUST HAVE [0..1] values",confidenceIterator.hasNext()); //STANBOL-630: confidence [0..1] @@ -677,7 +675,7 @@ public final class EnhancementStructureH assertTrue("fise:confidence MUST BE >= 0 (value= '"+confidence +"',enhancement "+enhancement+")", 0.0 <= confidence.doubleValue()); - Resource expectedConfidence = expectedValues.get(Properties.ENHANCER_CONFIDENCE); + RDFTerm expectedConfidence = expectedValues.get(Properties.ENHANCER_CONFIDENCE); if(expectedConfidence != null){ assertEquals("The fise:confidence for enhancement " +enhancement+" does not have the expected value", expectedConfidence,confidenceResource); @@ -688,10 +686,10 @@ public final class EnhancementStructureH } //validate that the (optional) dc:type is an URI and that there are not multiple values Iterator<Triple> dcTypeIterator = enhancements.filter(enhancement, Properties.DC_TYPE, null); - Resource expectedDcType = expectedValues.get(Properties.DC_TYPE); + RDFTerm expectedDcType = expectedValues.get(Properties.DC_TYPE); if(dcTypeIterator.hasNext()){ //dc:type is optional - Resource dcTypeResource = dcTypeIterator.next().getObject(); - assertTrue("dc:type values MUST BE URIs",dcTypeResource instanceof UriRef); + RDFTerm dcTypeResource = dcTypeIterator.next().getObject(); + assertTrue("dc:type values MUST BE URIs",dcTypeResource instanceof IRI); if(expectedDcType != null) { assertEquals("The dc:type value is not the expected "+expectedDcType+"!", expectedDcType,dcTypeResource); @@ -701,15 +699,15 @@ public final class EnhancementStructureH //validate the fise:confidence-value introduced by STANBOL-631 Iterator<Triple> confidenceLevelIterator = enhancements.filter( enhancement, Properties.ENHANCER_CONFIDENCE_LEVEL, null); - Resource expectedConfidenceValue = expectedValues.get(Properties.ENHANCER_CONFIDENCE_LEVEL); + RDFTerm expectedConfidenceValue = expectedValues.get(Properties.ENHANCER_CONFIDENCE_LEVEL); if(confidenceLevelIterator.hasNext()){ - Resource confidenceLevelResource = confidenceLevelIterator.next().getObject(); + RDFTerm confidenceLevelResource = confidenceLevelIterator.next().getObject(); assertTrue("fise:confidence-level values MUST BE URIs but found "+confidenceLevelResource, - confidenceLevelResource instanceof UriRef); + confidenceLevelResource instanceof IRI); assertNotNull("The fise:confidence-level value MUST BE one of the four " + "values defined in the ontology! (found: "+ confidenceLevelResource + " | enhancement " + enhancement+")", - CONFIDENCE_LEVEL_ENUM.getConfidenceLevel((UriRef)confidenceLevelResource)); + CONFIDENCE_LEVEL_ENUM.getConfidenceLevel((IRI)confidenceLevelResource)); assertFalse("The fise:confidence-level property is functional and MUST " + "HAVE only a single value (enhancement " + enhancement+")!",confidenceLevelIterator.hasNext()); @@ -731,13 +729,13 @@ public final class EnhancementStructureH * @return the number of found and validated TopicAnnotations. */ @SuppressWarnings("unchecked") - public static int validateAllTopicAnnotations(TripleCollection enhancements,Map<UriRef,Resource> expectedValues) { + public static int validateAllTopicAnnotations(Graph enhancements,Map<IRI,RDFTerm> expectedValues) { expectedValues = expectedValues == null ? Collections.EMPTY_MAP : expectedValues; Iterator<Triple> topicAnnotationIterator = enhancements.filter(null, RDF_TYPE, ENHANCER_TOPICANNOTATION); int topicAnnotationCount = 0; while (topicAnnotationIterator.hasNext()) { - UriRef topicAnnotation = (UriRef) topicAnnotationIterator.next().getSubject(); + IRI topicAnnotation = (IRI) topicAnnotationIterator.next().getSubject(); // test if selected Text is added validateTopicAnnotation(enhancements, topicAnnotation, expectedValues); @@ -750,12 +748,12 @@ public final class EnhancementStructureH * Checks if a fise:TopicAnnotation is valid as defined by * <a herf="https://issues.apache.org/jira/browse/STANBOL-617">STANBOL-617</a>. * NOTE that this also validates all fise:Enhancement related requirements by - * calling {@link #validateEnhancement(TripleCollection, UriRef, Map)} + * calling {@link #validateEnhancement(Graph, IRI, Map)} * @param enhancements the enhancements graph * @param topicAnnotation the topic annotation to validate * @param expectedValues expected values (properties for the values are used as keys) */ - public static void validateTopicAnnotation(TripleCollection enhancements, UriRef topicAnnotation, Map<UriRef,Resource> expectedValues){ + public static void validateTopicAnnotation(Graph enhancements, IRI topicAnnotation, Map<IRI,RDFTerm> expectedValues){ //validate the rdf:type Iterator<Triple> rdfTypeIterator = enhancements.filter(topicAnnotation, RDF_TYPE, ENHANCER_TOPICANNOTATION); assertTrue("Parsed Enhancement "+topicAnnotation +" is missing the fise:TopicAnnotation type ", @@ -771,7 +769,7 @@ public final class EnhancementStructureH assertTrue(relationToTextAnnotationIterator.hasNext()); while (relationToTextAnnotationIterator.hasNext()) { // test if the referred annotations are text annotations - UriRef referredTextAnnotation = (UriRef) relationToTextAnnotationIterator.next().getObject(); + IRI referredTextAnnotation = (IRI) relationToTextAnnotationIterator.next().getObject(); assertTrue(enhancements.filter(referredTextAnnotation, RDF_TYPE, ENHANCER_TEXTANNOTATION).hasNext()); } @@ -780,11 +778,11 @@ public final class EnhancementStructureH // fise:EntityAnnotations this property is NOT required - cardinality [0..*] Iterator<Triple> entityReferenceIterator = enhancements.filter(topicAnnotation, ENHANCER_ENTITY_REFERENCE, null); - Resource expectedReferencedEntity = expectedValues.get(ENHANCER_ENTITY_REFERENCE); + RDFTerm expectedReferencedEntity = expectedValues.get(ENHANCER_ENTITY_REFERENCE); while(entityReferenceIterator.hasNext()){ //check possible multiple references - Resource entityReferenceResource = entityReferenceIterator.next().getObject(); + RDFTerm entityReferenceResource = entityReferenceIterator.next().getObject(); // test if the reference is an URI - assertTrue("fise:entity-reference value MUST BE of URIs",entityReferenceResource instanceof UriRef); + assertTrue("fise:entity-reference value MUST BE of URIs",entityReferenceResource instanceof IRI); if(expectedReferencedEntity != null && expectedReferencedEntity.equals(entityReferenceResource)){ expectedReferencedEntity = null; //found } @@ -795,11 +793,11 @@ public final class EnhancementStructureH //test if the entity label is set (required) Iterator<Triple> entityLabelIterator = enhancements.filter(topicAnnotation, ENHANCER_ENTITY_LABEL, null); assertTrue(entityLabelIterator.hasNext()); - Resource expectedEntityLabel = expectedValues.get(ENHANCER_ENTITY_LABEL); + RDFTerm expectedEntityLabel = expectedValues.get(ENHANCER_ENTITY_LABEL); while(entityLabelIterator.hasNext()){ - Resource entityLabelResource = entityLabelIterator.next().getObject(); + RDFTerm entityLabelResource = entityLabelIterator.next().getObject(); assertTrue("fise:entity-label values MUST BE PlainLiterals (EntityAnnotation: "+topicAnnotation+")!", - entityLabelResource instanceof PlainLiteral); + entityLabelResource instanceof Literal); if(expectedEntityLabel != null && expectedEntityLabel.equals(entityLabelResource)){ expectedEntityLabel = null; } @@ -809,10 +807,10 @@ public final class EnhancementStructureH // test fise:entity-type(s). NOTE: this is not required - cardinality [0..*] Iterator<Triple> entityTypeIterator = enhancements.filter(topicAnnotation, Properties.ENHANCER_ENTITY_TYPE, null); - Resource expectedEntityType = expectedValues.get(Properties.ENHANCER_ENTITY_TYPE); + RDFTerm expectedEntityType = expectedValues.get(Properties.ENHANCER_ENTITY_TYPE); if(entityTypeIterator.hasNext()){ - Resource entityTypeResource = entityTypeIterator.next().getObject(); - assertTrue("fise:entity-type values MUST BE URIs",entityTypeResource instanceof UriRef); + RDFTerm entityTypeResource = entityTypeIterator.next().getObject(); + assertTrue("fise:entity-type values MUST BE URIs",entityTypeResource instanceof IRI); if(expectedEntityType != null && expectedEntityType.equals(entityTypeResource)){ expectedEntityType = null; //found } Modified: stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java?rev=1744328&r1=1744327&r2=1744328&view=diff ============================================================================== --- stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java (original) +++ stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java Tue May 17 22:20:49 2016 @@ -63,11 +63,11 @@ import javax.ws.rs.core.UriInfo; import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.Provider; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.IRI; +import org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl; +import org.apache.clerezza.commons.rdf.impl.utils.TripleImpl; import org.apache.clerezza.rdf.core.LiteralFactory; -import org.apache.clerezza.rdf.core.MGraph; -import org.apache.clerezza.rdf.core.UriRef; -import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl; -import org.apache.clerezza.rdf.core.impl.TripleImpl; import org.apache.clerezza.rdf.core.serializedform.Parser; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; @@ -80,7 +80,7 @@ import org.apache.felix.scr.annotations. import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; -import org.apache.stanbol.commons.indexedgraph.IndexedMGraph; +import org.apache.stanbol.commons.indexedgraph.IndexedGraph; import org.apache.stanbol.enhancer.servicesapi.Blob; import org.apache.stanbol.enhancer.servicesapi.ContentItem; import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory; @@ -147,7 +147,7 @@ public class ContentItemReader implement InputStream entityStream) throws IOException, WebApplicationException { //boolean withMetadata = withMetadata(httpHeaders); ContentItem contentItem = null; - UriRef contentItemId = getContentItemId(); + IRI contentItemId = getContentItemId(); if(log.isTraceEnabled()){ //NOTE: enabling TRACE level logging will copy the parsed content // into a BYTE array @@ -166,7 +166,7 @@ public class ContentItemReader implement if(mediaType.isCompatible(MULTIPART)){ log.debug(" - parse Multipart MIME ContentItem"); //try to read ContentItem from "multipart/from-data" - MGraph metadata = null; + Graph metadata = null; FileItemIterator fileItemIterator; try { fileItemIterator = fu.getItemIterator(new MessageBodyReaderContext(entityStream, mediaType)); @@ -183,9 +183,9 @@ public class ContentItemReader implement //the metadata may define the ID for the contentItem //only used if not parsed as query param if(contentItemId == null && fis.getName() != null && !fis.getName().isEmpty()){ - contentItemId = new UriRef(fis.getName()); + contentItemId = new IRI(fis.getName()); } - metadata = new IndexedMGraph(); + metadata = new IndexedGraph(); try { getParser().parse(metadata, fis.openStream(), fis.getContentType()); } catch (Exception e) { @@ -254,7 +254,7 @@ public class ContentItemReader implement "MUST define the contentParts URI as" + "'name' of the MIME part!").build()); } - MGraph graph = new IndexedMGraph(); + Graph graph = new IndexedGraph(); try { getParser().parse(graph, fis.openStream(), fis.getContentType()); } catch (Exception e) { @@ -265,7 +265,7 @@ public class ContentItemReader implement fis.getName(),fis.getContentType())) .build()); } - UriRef contentPartId = new UriRef(fis.getFieldName()); + IRI contentPartId = new IRI(fis.getFieldName()); contentItem.addPart(contentPartId, graph); } } @@ -316,8 +316,8 @@ public class ContentItemReader implement * @param lang the parsed language */ private void createParsedLanguageAnnotation(ContentItem ci, String lang){ - MGraph m = ci.getMetadata(); - UriRef la = new UriRef("urn:enhancement-"+ EnhancementEngineHelper.randomUUID()); + Graph m = ci.getMetadata(); + IRI la = new IRI("urn:enhancement-"+ EnhancementEngineHelper.randomUUID()); //add the fise:Enhancement information m.add(new TripleImpl(la, RDF_TYPE, ENHANCER_ENHANCEMENT)); m.add(new TripleImpl(la, RDF_TYPE, ENHANCER_TEXTANNOTATION)); @@ -335,7 +335,7 @@ public class ContentItemReader implement * {@link #request}. * @return the parsed URI or <code>null</code> if none */ - private UriRef getContentItemId() { + private IRI getContentItemId() { //NOTE: check for request NULL is needed because of unit tests if (uriInfo == null) return null; URI uri = uriInfo.getRequestUri(); @@ -377,7 +377,7 @@ public class ContentItemReader implement + "of the " + source, Response.Status.BAD_REQUEST); } } - return ciUri == null ? null : new UriRef(ciUri); + return ciUri == null ? null : new IRI(ciUri); } /** * Getter for the <code>Content-Language</code> header @@ -458,7 +458,7 @@ public class ContentItemReader implement * @throws FileUploadException if the parsed contents are not correctly * encoded Multipart MIME */ - private ContentItem createContentItem(UriRef id, MGraph metadata, FileItemStream content,Set<String> parsedContentParts) throws IOException, FileUploadException { + private ContentItem createContentItem(IRI id, Graph metadata, FileItemStream content,Set<String> parsedContentParts) throws IOException, FileUploadException { MediaType partContentType = MediaType.valueOf(content.getContentType()); ContentItem contentItem = null; ContentItemFactory ciFactory = getContentItemFactory(); @@ -479,13 +479,13 @@ public class ContentItemReader implement } else { log.debug(" - create Blob for content (type:{})", fis.getContentType()); Blob blob = ciFactory.createBlob(new StreamSource(fis.openStream(), fis.getContentType())); - UriRef contentPartId = null; + IRI contentPartId = null; if(fis.getFieldName() != null && !fis.getFieldName().isEmpty()){ - contentPartId = new UriRef(fis.getFieldName()); + contentPartId = new IRI(fis.getFieldName()); } else { //generating a random ID might break metadata //TODO maybe we should throw an exception instead - contentPartId = new UriRef("urn:contentpart:"+ randomUUID()); + contentPartId = new IRI("urn:contentpart:"+ randomUUID()); } log.debug(" ... add Blob {} to ContentItem {} with content (type:{})", new Object[]{contentPartId, id, fis.getContentType()}); Modified: stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java?rev=1744328&r1=1744327&r2=1744328&view=diff ============================================================================== --- stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java (original) +++ stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java Tue May 17 22:20:49 2016 @@ -51,9 +51,9 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.UriInfo; -import org.apache.clerezza.rdf.core.MGraph; -import org.apache.clerezza.rdf.core.TripleCollection; -import org.apache.clerezza.rdf.core.UriRef; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.IRI; import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource; import org.apache.stanbol.commons.web.base.resource.LayoutConfiguration; import org.apache.stanbol.commons.web.base.resource.TemplateLayoutConfiguration; @@ -186,13 +186,13 @@ public abstract class AbstractEnhancerRe } reqProp.put(OMIT_PARSED_CONTENT, omitParsed); if(contentParts != null && !contentParts.isEmpty()){ - Set<UriRef> outputContentParts = new HashSet<UriRef>(); + Set<IRI> outputContentParts = new HashSet<IRI>(); for(String contentPartUri : contentParts){ if(contentPartUri != null && !contentPartUri.isEmpty()){ if("*".equals(contentPartUri)){ outputContentParts.add(null); //indicated wildcard } else { - outputContentParts.add(new UriRef(contentPartUri)); + outputContentParts.add(new IRI(contentPartUri)); } } } @@ -230,11 +230,11 @@ public abstract class AbstractEnhancerRe if (jobManager != null) { jobManager.enhanceContent(ci, getChain()); } - MGraph graph = ci.getMetadata(); + Graph graph = ci.getMetadata(); Boolean includeExecutionMetadata = RequestPropertiesHelper.isIncludeExecutionMetadata(reqProp); if (includeExecutionMetadata != null && includeExecutionMetadata.booleanValue()) { try { - graph.addAll(ci.getPart(ExecutionMetadata.CHAIN_EXECUTION, TripleCollection.class)); + graph.addAll(ci.getPart(ExecutionMetadata.CHAIN_EXECUTION, Graph.class)); } catch (NoSuchPartException e) { // no executionMetadata available } Modified: stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ChainsRootResource.java URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ChainsRootResource.java?rev=1744328&r1=1744327&r2=1744328&view=diff ============================================================================== --- stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ChainsRootResource.java (original) +++ stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ChainsRootResource.java Tue May 17 22:20:49 2016 @@ -45,8 +45,8 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; -import org.apache.clerezza.rdf.core.MGraph; -import org.apache.clerezza.rdf.core.impl.SimpleMGraph; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph; import org.apache.clerezza.rdf.core.serializedform.Serializer; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; @@ -180,7 +180,7 @@ public class ChainsRootResource extends @Produces(value={JSON_LD, APPLICATION_JSON,N3,N_TRIPLE,RDF_JSON,RDF_XML,TURTLE,X_TURTLE}) public Response getEngines(@Context HttpHeaders headers){ String rootUrl = uriInfo.getBaseUriBuilder().path(getRootUrl()).build().toString(); - MGraph graph = new SimpleMGraph(); + Graph graph = new SimpleGraph(); addActiveChains(getActiveChains(), chainTracker.getDefault(),graph,rootUrl); ResponseBuilder res = Response.ok(graph); //addCORSOrigin(servletContext,res, headers);
