Added:
incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfRepresentationTest.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfRepresentationTest.java?rev=1058959&view=auto
==============================================================================
---
incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfRepresentationTest.java
(added)
+++
incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfRepresentationTest.java
Fri Jan 14 11:39:26 2011
@@ -0,0 +1,184 @@
+package eu.iksproject.rick.model.clerezza;
+
+import static junit.framework.Assert.*;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Language;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.PlainLiteral;
+import org.apache.clerezza.rdf.core.TypedLiteral;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+import eu.iksproject.rick.servicesapi.model.Representation;
+import eu.iksproject.rick.servicesapi.model.Text;
+import eu.iksproject.rick.servicesapi.model.ValueFactory;
+import eu.iksproject.rick.test.model.RepresentationTest;
+
+public class RdfRepresentationTest extends RepresentationTest {
+
+ protected ValueFactory valueFactory;
+ protected LiteralFactory literalFactory;
+
+ @Before
+ public void init(){
+ this.valueFactory = RdfValueFactory.getInstance();
+ this.literalFactory = LiteralFactory.getInstance();
+ }
+
+ @Override
+ protected Object getUnsupportedValueInstance() {
+ return null; //indicates that all kinds of Objects are supported!
+ }
+
+ @Override
+ protected ValueFactory getValueFactory() {
+ return valueFactory;
+ }
+
/*--------------------------------------------------------------------------
+ * Additional Tests for special Features of the Clerezza based
implementation
+ *
+ * This includes mainly support for additional types like PlainLiteral,
+ * TypedLiteral, UriRefs. The conversion to such types as well as getter
for
+ * such types.
+
*--------------------------------------------------------------------------
+ */
+ /**
+ * {@link PlainLiteral} is used for natural language text in the Clerezza
+ * RDF API. This tests if adding {@link PlainLiteral}s to the
+ * {@link Representation#add(String, Object)} method makes them available
+ * as {@link Text} instances via the {@link Representation} API (e.g.
+ * {@link Representation#get(String, String...)}).
+ */
+ @Test
+ public void testPlainLiteralToTextConversion(){
+ String field = "urn:test.RdfRepresentation:test.field";
+ PlainLiteral noLangLiteral = new PlainLiteralImpl("A plain literal
without Language");
+ PlainLiteral enLiteral = new PlainLiteralImpl("An english literal",new
Language("en"));
+ PlainLiteral deLiteral = new PlainLiteralImpl("Ein Deutsches
Literal",new Language("de"));
+ PlainLiteral deATLiteral = new PlainLiteralImpl("Ein Topfen Verband
hilft bei Zerrungen",new Language("de-AT"));
+ Collection<PlainLiteral> plainLiterals =
Arrays.asList(noLangLiteral,enLiteral,deLiteral,deATLiteral);
+ Representation rep = createRepresentation(null);
+ rep.add(field, plainLiterals);
+ //now test, that the Plain Literals are available as natural language
+ //tests via the Representation Interface!
+ //1) one without a language
+ Iterator<Text> noLangaugeTexts = rep.get(field, (String)null);
+ assertTrue(noLangaugeTexts.hasNext());
+ Text noLanguageText = noLangaugeTexts.next();
+ assertEquals(noLangLiteral.getLexicalForm(), noLanguageText.getText());
+ assertNull(noLanguageText.getLanguage());
+ assertFalse(noLangaugeTexts.hasNext()); //only a single result
+ //2) one with a language
+ Iterator<Text> enLangaugeTexts = rep.get(field, "en");
+ assertTrue(enLangaugeTexts.hasNext());
+ Text enLangageText = enLangaugeTexts.next();
+ assertEquals(enLiteral.getLexicalForm(), enLangageText.getText());
+ assertEquals(enLiteral.getLanguage().toString(),
enLangageText.getLanguage());
+ assertFalse(enLangaugeTexts.hasNext());//only a single result
+ //3) test to get all natural language values
+ Set<String> stringValues = new HashSet<String>();
+ for(PlainLiteral plainLiteral : plainLiterals){
+ stringValues.add(plainLiteral.getLexicalForm());
+ }
+ Iterator<Text> texts = rep.getText(field);
+ while(texts.hasNext()){
+ assertTrue(stringValues.remove(texts.next().getText()));
+ }
+ assertTrue(stringValues.isEmpty());
+ }
+ /**
+ * {@link TypedLiteral}s are used to represent literal values for different
+ * xsd dataTypes within Clerezza. This method tests of {@link
TypedLiteral}s
+ * with the data type xsd:string are correctly treated like {@link String}
+ * values. This tests especially if they are treated as natural language
+ * texts without language.
+ */
+ @Test
+ public void testTypedLiteralToTextConversion(){
+ String field = "urn:test.RdfRepresentation:test.field";
+ TypedLiteral stringLiteral = literalFactory.createTypedLiteral("This
is a stirng value");
+ //also add an integer to test that other typed literals are not used
as texts
+ TypedLiteral integerLiteral = literalFactory.createTypedLiteral(new
Integer(5));
+ Representation rep = createRepresentation(null);
+ rep.add(field, Arrays.asList(stringLiteral,integerLiteral));
+ //test if the literal is returned when asking for natural language
text without language
+ Iterator<Text> noLangTexts = rep.get(field, (String)null);
+ assertTrue(noLangTexts.hasNext());
+ assertEquals(stringLiteral.getLexicalForm(),
noLangTexts.next().getText());
+ assertFalse(noLangTexts.hasNext());
+ //test that string literals are returned when asking for all natural
language text values
+ Iterator<Text> texts = rep.getText(field);
+ assertTrue(texts.hasNext());
+ assertEquals(stringLiteral.getLexicalForm(), texts.next().getText());
+ assertFalse(texts.hasNext());
+ }
+ /**
+ * {@link TypedLiteral}s are used to represent literal values for different
+ * xsd dataTypes within Clerezza. This method tests if xsd dataTypes are
+ * converted to the corresponding java types.
+ * This is dependent on the {@link LiteralFactory} implementation used by
+ * the {@link RdfRepresentation} implementation.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testTypedLiteralToValueConversion(){
+ String field = "urn:test.RdfRepresentation:test.field";
+ Integer integerValue = 5;
+ TypedLiteral integerLiteral =
literalFactory.createTypedLiteral(integerValue);
+ Date dateValue = new Date();
+ TypedLiteral dateLiteeral =
literalFactory.createTypedLiteral(dateValue);
+ Double doubleValue = Math.PI;
+ TypedLiteral doubleLiteral =
literalFactory.createTypedLiteral(doubleValue);
+ String stringValue = "This is a string literal value";
+ TypedLiteral stringLiteral =
literalFactory.createTypedLiteral(stringValue);
+ Representation rep = createRepresentation(null);
+ Collection<TypedLiteral> typedLiterals =
+
Arrays.asList(integerLiteral,doubleLiteral,stringLiteral,dateLiteeral);
+ rep.add(field, typedLiterals);
+
+ //now check that such values are available via TypedLiteral
+ Iterator<TypedLiteral> typedLiteralValues = rep.get(field,
TypedLiteral.class);
+ int size = 0;
+ while(typedLiteralValues.hasNext()){
+ assertTrue(typedLiterals.contains(typedLiteralValues.next()));
+ size++;
+ }
+ assertTrue(typedLiterals.size() == size);
+
+ //now check that the values are available via the java object types
+ //1) integer
+ Iterator<Integer> intValues = rep.get(field, Integer.class);
+ assertTrue(intValues.hasNext());
+ assertEquals(integerValue, intValues.next());
+ assertFalse(intValues.hasNext());
+ //2) double
+ Iterator<Double> doubleValues = rep.get(field, Double.class);
+ assertTrue(doubleValues.hasNext());
+ assertEquals(doubleValue, doubleValues.next());
+ assertFalse(doubleValues.hasNext());
+ //3) string
+ Iterator<String> stringValues = rep.get(field, String.class);
+ assertTrue(stringValues.hasNext());
+ assertEquals(stringValue, stringValues.next());
+ assertFalse(stringValues.hasNext());
+ //4) date
+ Iterator<Date> dateValues = rep.get(field,Date.class);
+ assertTrue(dateValues.hasNext());
+ assertEquals(dateValue, dateValues.next());
+ assertFalse(dateValues.hasNext());
+ }
+ //TODO add tests for adding Integers, Doubles, ... and getting
TypedLiterals
+ public static void main(String[] args) {
+ RdfRepresentationTest test = new RdfRepresentationTest();
+ test.init();
+ test.testTypedLiteralToValueConversion();
+ }
+}
Propchange:
incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfRepresentationTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfValueFactoryTest.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfValueFactoryTest.java?rev=1058959&view=auto
==============================================================================
---
incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfValueFactoryTest.java
(added)
+++
incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfValueFactoryTest.java
Fri Jan 14 11:39:26 2011
@@ -0,0 +1,45 @@
+package eu.iksproject.rick.model.clerezza;
+
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.junit.Before;
+import org.junit.Test;
+
+import eu.iksproject.rick.servicesapi.model.ValueFactory;
+import eu.iksproject.rick.test.model.ValueFactoryTest;
+
+public class RdfValueFactoryTest extends ValueFactoryTest {
+
+ protected RdfValueFactory valueFactory;
+
+ @Before
+ public void init(){
+ this.valueFactory = RdfValueFactory.getInstance();
+ }
+
+ @Override
+ protected Object getUnsupportedReferenceType() {
+ return null; //all references are supported (no test for valid IRIs
are done by Clerezza)
+ }
+
+ @Override
+ protected Object getUnsupportedTextType() {
+ return null; //all Types are supported
+ }
+
+ @Override
+ protected ValueFactory getValueFactory() {
+ return valueFactory;
+ }
+ @Test(expected=NullPointerException.class)
+ public void testNullNodeRepresentation() {
+ SimpleMGraph graph = new SimpleMGraph();
+ valueFactory.createRdfRepresentation(null, graph);
+ }
+ @Test(expected=NullPointerException.class)
+ public void testNullGraphRepresentation() {
+ UriRef rootNode = new UriRef("urn:test.rootNode");
+ valueFactory.createRdfRepresentation(rootNode, null);
+ }
+
+}
Propchange:
incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfValueFactoryTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/impl/SolrYard.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/impl/SolrYard.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
---
incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/impl/SolrYard.java
(original)
+++
incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/impl/SolrYard.java
Fri Jan 14 11:39:26 2011
@@ -298,10 +298,10 @@ public class SolrYard extends AbstractYa
long queryGeneration = System.currentTimeMillis();
final Set<String> selected;
if(select == SELECT.QUERY){
- //if query set the fields to add to the result Representations
- selected = parsedQuery.getSelectedFields();
- //add the score to query results!
- selected.add(RdfResourceEnum.resultScore.getUri());
+ //if query set the fields to add to the result
Representations
+ selected = new
HashSet<String>(parsedQuery.getSelectedFields());
+ //add the score to query results!
+ selected.add(RdfResourceEnum.resultScore.getUri());
} else {
//otherwise add all fields
selected = null;