You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2013/10/03 16:28:34 UTC
svn commit: r1528887 - in /clerezza/trunk/rdf.cris:
core/src/main/java/org/apache/clerezza/rdf/cris/
core/src/test/java/org/apache/clerezza/rdf/cris/
ontologies/src/main/resources/org/apache/clerezza/rdf/cris/ontologies/
Author: reto
Date: Thu Oct 3 14:28:34 2013
New Revision: 1528887
URL: http://svn.apache.org/r1528887
Log:
CLEREZZA-828: Virtual properties can now be declared as FacetProperties
Modified:
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/IndexDefinitionManager.java
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PathVirtualProperty.java
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/TermRangeCondition.java
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java
clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/WildcardCondition.java
clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.java
clerezza/trunk/rdf.cris/ontologies/src/main/resources/org/apache/clerezza/rdf/cris/ontologies/cris.ttl
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java Thu Oct 3 14:28:34 2013
@@ -810,13 +810,16 @@ public class GraphIndexer extends Resour
if (vPropertyList == null) {
vPropertyList = new ArrayList<VirtualProperty>();
}
- return new JoinVirtualProperty(getVirtualPropertyList(r, vPropertyList));
+ return new JoinVirtualProperty(getVirtualPropertyList(r, vPropertyList),
+ r.hasProperty(RDF.type, CRIS.FacetProperty));
} else {
if (r.hasProperty(RDF.type, CRIS.PathVirtualProperty)) {
- return new PathVirtualProperty(getUriPropertyList(r));
+ return new PathVirtualProperty(getUriPropertyList(r),
+ r.hasProperty(RDF.type, CRIS.FacetProperty));
} else {
if ((r.getNode()) instanceof UriRef) {
- return new PropertyHolder((UriRef) r.getNode());
+ return new PropertyHolder((UriRef) r.getNode(),
+ r.hasProperty(RDF.type, CRIS.FacetProperty));
} else {
throw new RuntimeException(r + " is not of a knows VirtualProperty type and its not a UriRef (it's a " + (r.getNode()).getClass() + ")");
}
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/IndexDefinitionManager.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/IndexDefinitionManager.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/IndexDefinitionManager.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/IndexDefinitionManager.java Thu Oct 3 14:28:34 2013
@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.List;
import org.apache.clerezza.rdf.core.BNode;
import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
import org.apache.clerezza.rdf.core.Resource;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.impl.TripleImpl;
@@ -51,17 +52,29 @@ public class IndexDefinitionManager {
}
/**
- * Defines an index for the specified types and properties, removing
- * previous index definitions for that type (java friendly version)
+ * Defines an index for the specified type and properties, removing
+ * previous index definitions for that type (java friendly version) with
+ * facet search enabled on all properties
*
* @param rdfType The RDF type for which to build an index.
* @param properties A list of RDF properties to index.
*/
public void addDefinition(UriRef rdfType, List<UriRef> properties) {
+ addDefinition(rdfType, properties, true);
+ }
+ /**
+ * Defines an index for the specified type and properties, removing
+ * previous index definitions for that type (java friendly version)
+ *
+ * @param rdfType The RDF type for which to build an index.
+ * @param properties A list of RDF properties to index.
+ * @param facetSearch true if all properties shall be facet properties false if none
+ */
+ public void addDefinition(UriRef rdfType, List<UriRef> properties, boolean facetSearch) {
List<VirtualProperty> list = new ArrayList<VirtualProperty>();
for (UriRef uri : properties) {
- list.add(new PropertyHolder(uri));
+ list.add(new PropertyHolder(uri, facetSearch));
}
addDefinitionVirtual(rdfType, list);
}
@@ -98,7 +111,13 @@ public class IndexDefinitionManager {
}
private Resource asResource(VirtualProperty vp) {
-
+ final NonLiteral vpResource = asResourceTypeSpecific(vp);
+ if (vp.isFacetProperty()) {
+ definitionGraph.add(new TripleImpl(vpResource, RDF.type, CRIS.FacetProperty));
+ }
+ return vpResource;
+ }
+ private NonLiteral asResourceTypeSpecific(VirtualProperty vp) {
if (vp instanceof PropertyHolder) {
return ((PropertyHolder) vp).property;
} else if (vp instanceof JoinVirtualProperty) {
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java Thu Oct 3 14:28:34 2013
@@ -38,11 +38,23 @@ public class JoinVirtualProperty extends
List<VirtualProperty> properties;
/**
- * Creates a JoinVirtualPorperty from the supplied properties.
+ * Creates a JoinVirtualPorperty from the supplied properties
+ * with facet search enabled.
*
* @param properties the properties.
*/
public JoinVirtualProperty(List<VirtualProperty> properties) {
+ this(properties, true);
+ }
+
+ /**
+ * Creates a JoinVirtualPorperty from the supplied properties.
+ *
+ * @param properties the properties.
+ */
+ public JoinVirtualProperty(List<VirtualProperty> properties,
+ boolean facetProperty) {
+ super(facetProperty);
this.stringKey = "J" + VirtualProperty.listDigest(properties);
this.properties = properties;
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PathVirtualProperty.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PathVirtualProperty.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PathVirtualProperty.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PathVirtualProperty.java Thu Oct 3 14:28:34 2013
@@ -40,15 +40,25 @@ public class PathVirtualProperty extends
List<UriRef> properties;
/**
+ * Creates a new PathVirtualProperty with face search enabled
+ *
+ * @param properties
+ */
+ public PathVirtualProperty(List<UriRef> properties) {
+ this(properties, true);
+ }
+ /**
* Creates a new PathVirtualProperty.
*
* @param properties An ordered list specifying the path.
*/
- public PathVirtualProperty(List<UriRef> properties) {
+ public PathVirtualProperty(List<UriRef> properties, boolean facetProperty) {
+ super(facetProperty);
this.properties = properties;
List<VirtualProperty> list = new ArrayList<VirtualProperty>();
for (UriRef p : this.properties) {
- list.add(new PropertyHolder(p));
+ //facetProperty is not digest relevant
+ list.add(new PropertyHolder(p,false));
}
this.baseProperties = new HashSet<UriRef>(properties);
this.stringKey = "P" + VirtualProperty.listDigest(list);
@@ -76,7 +86,8 @@ public class PathVirtualProperty extends
private void getPathResults(GraphNode node, List<UriRef> properties, List<String> list) {
if (properties.size() == 1) {
- list.addAll(new PropertyHolder(properties.get(0)).value(node));
+ //being a facet property or not is irrelevant for the result
+ list.addAll(new PropertyHolder(properties.get(0), false).value(node));
} else {
Lock lock = node.readLock();
lock.lock();
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java Thu Oct 3 14:28:34 2013
@@ -42,11 +42,22 @@ public class PropertyHolder extends Virt
UriRef property;
/**
- * Creates a new PropertyHolder that wraps an RDF property.
+ * Creates a new PropertyHolder that wraps an RDF property with facet
+ * search enabled.
*
* @param property the property to wrap.
*/
public PropertyHolder(UriRef property) {
+ this(property, true);
+ }
+
+ /**
+ * Creates a new PropertyHolder that wraps an RDF property.
+ *
+ * @param property the property to wrap.
+ */
+ public PropertyHolder(UriRef property, boolean facetProperty) {
+ super(facetProperty);
this.property = property;
stringKey = property.getUnicodeString();
baseProperties = new HashSet();
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java Thu Oct 3 14:28:34 2013
@@ -144,7 +144,8 @@ import org.apache.lucene.queryparser.cla
if(escapePattern) {
pattern = QueryParser.escape(pattern);
}
- list.add(new WildcardCondition(new PropertyHolder(property), pattern));
+ //on the search side of thing it is irrelevant how the facetProperty flag is set
+ list.add(new WildcardCondition(new PropertyHolder(property, false), pattern));
return findResources(list, facetCollectors);
}
@@ -169,7 +170,8 @@ import org.apache.lucene.queryparser.cla
if(escapePattern) {
pattern = QueryParser.escape(pattern);
}
- list.add(new WildcardCondition(new PropertyHolder(property), pattern));
+ //on the search side of thing it is irrelevant how the facetProperty flag is set
+ list.add(new WildcardCondition(new PropertyHolder(property, false), pattern));
return findResources(list, sortSpecification, facetCollectors);
}
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/TermRangeCondition.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/TermRangeCondition.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/TermRangeCondition.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/TermRangeCondition.java Thu Oct 3 14:28:34 2013
@@ -83,7 +83,8 @@ public class TermRangeCondition extends
*/
public TermRangeCondition(UriRef uriRefProperty, String lowerTerm,String upperTerm,
boolean includeUpper, boolean includeLower) {
- this(new PropertyHolder(uriRefProperty), lowerTerm, upperTerm, includeUpper, includeLower);
+ //on the search side of thing it is irrelevant how the facetProperty flag is set
+ this(new PropertyHolder(uriRefProperty, false), lowerTerm, upperTerm, includeUpper, includeLower);
}
@Override
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java Thu Oct 3 14:28:34 2013
@@ -39,6 +39,18 @@ import org.wymiwyg.commons.util.Util;
* @see PropertyHolder
*/
public abstract class VirtualProperty {
+
+
+ protected VirtualProperty(boolean facetProperty) {
+ this.facetProperty = facetProperty;
+ }
+
+
+ /**
+ * true if this is a facet property, false otherwise
+ */
+ private final boolean facetProperty;
+
/**
* As opposed to toString this doesn't need to be human readable but unique (as with
* a strong hash.
@@ -51,6 +63,13 @@ public abstract class VirtualProperty {
Set<UriRef> baseProperties;
/**
+ * @return true if this is a facet property, false otherwise
+ */
+ public boolean isFacetProperty() {
+ return facetProperty;
+ }
+
+ /**
* Returns the key of this property.
*
* @return the key.
Modified: clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/WildcardCondition.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/WildcardCondition.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/WildcardCondition.java (original)
+++ clerezza/trunk/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/WildcardCondition.java Thu Oct 3 14:28:34 2013
@@ -61,7 +61,8 @@ public class WildcardCondition extends C
* @param pattern the search query
*/
public WildcardCondition(UriRef uriRefProperty,String pattern) {
- this(new PropertyHolder(uriRefProperty), pattern);
+ //on the search side of thing it is irrelevant how the facetProperty flag is set
+ this(new PropertyHolder(uriRefProperty, false), pattern);
}
Modified: clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java (original)
+++ clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java Thu Oct 3 14:28:34 2013
@@ -58,6 +58,7 @@ public class GraphIndexerTest {
private void createDefinition(UriRef rdfType, List<UriRef> properties) {
GraphNode node = new GraphNode(new BNode(), definitions);
node.addProperty(RDF.type, CRIS.IndexDefinition);
+ node.addProperty(RDF.type, CRIS.FacetProperty);
node.addProperty(CRIS.indexedType, rdfType);
for (UriRef p : properties) {
node.addProperty(CRIS.indexedProperty, p);
@@ -260,7 +261,7 @@ public class GraphIndexerTest {
predicates.add(FOAF.firstName);
predicates.add(FOAF.lastName);
predicates.add(RDFS.comment);
- indexDefinitionManager.addDefinition(FOAF.Person, predicates);
+ indexDefinitionManager.addDefinition(FOAF.Person, predicates, true);
service.reCreateIndex();
Thread.sleep(1000);
{
Modified: clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.java?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.java (original)
+++ clerezza/trunk/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.java Thu Oct 3 14:28:34 2013
@@ -29,6 +29,7 @@ import org.apache.clerezza.rdf.core.BNod
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.Triple;
import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
import org.apache.clerezza.rdf.ontologies.FOAF;
import org.apache.clerezza.rdf.ontologies.RDF;
import org.apache.clerezza.rdf.cris.ontologies.CRIS;
@@ -41,35 +42,45 @@ import org.junit.Test;
public class IndexDefinitionManagerTest {
- private void createDefinition(UriRef rdfType, List<UriRef> properties, MGraph manuallyCreatedGraph) {
+ private void createDefinition(UriRef rdfType, List<UriRef> properties,
+ MGraph manuallyCreatedGraph, boolean facetProperty) {
GraphNode node = new GraphNode(new BNode(), manuallyCreatedGraph);
node.addProperty(RDF.type, CRIS.IndexDefinition);
node.addProperty(CRIS.indexedType, rdfType);
for (UriRef p : properties) {
node.addProperty(CRIS.indexedProperty, p);
+ if (facetProperty) {
+ manuallyCreatedGraph.add(new TripleImpl(p, RDF.type, CRIS.FacetProperty));
+ }
}
}
@Test
- public void createDefinitionGraph() {
-
+ public void createDefinitionGraphWithoutFacetProperties() {
+ createDefinitionGraph(false);
+ }
-
+ @Test
+ public void createDefinitionGraphWithFacetProperties() {
+ createDefinitionGraph(true);
+ }
+
+ public void createDefinitionGraph(boolean withFacetProperties) {
MGraph indexManagerGraph = new SimpleMGraph();
IndexDefinitionManager indexDefinitionManager = new IndexDefinitionManager(indexManagerGraph);
List<UriRef> properties = new java.util.ArrayList<UriRef>();
properties.add(FOAF.firstName);
properties.add(FOAF.lastName);
- indexDefinitionManager.addDefinition(FOAF.Person, properties);
+ indexDefinitionManager.addDefinition(FOAF.Person, properties, withFacetProperties);
List<UriRef> list = new ArrayList<UriRef>();
list.add(FOAF.firstName);
list.add(FOAF.lastName);
MGraph manuallyCreatedGraph = new SimpleMGraph();
- createDefinition(FOAF.Person, list, manuallyCreatedGraph);
+ createDefinition(FOAF.Person, list, manuallyCreatedGraph, withFacetProperties);
Assert.assertEquals(manuallyCreatedGraph.getGraph(), indexManagerGraph.getGraph());
}
-
+
@Test
public void createJoinIndexProperty() {
//import VirtualProperties._
Modified: clerezza/trunk/rdf.cris/ontologies/src/main/resources/org/apache/clerezza/rdf/cris/ontologies/cris.ttl
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.cris/ontologies/src/main/resources/org/apache/clerezza/rdf/cris/ontologies/cris.ttl?rev=1528887&r1=1528886&r2=1528887&view=diff
==============================================================================
--- clerezza/trunk/rdf.cris/ontologies/src/main/resources/org/apache/clerezza/rdf/cris/ontologies/cris.ttl (original)
+++ clerezza/trunk/rdf.cris/ontologies/src/main/resources/org/apache/clerezza/rdf/cris/ontologies/cris.ttl Thu Oct 3 14:28:34 2013
@@ -28,6 +28,11 @@
:IndexDefinition a rdfs:Class;
skos:definition "The description of an index that is to be maintained by CRIS."@en.
+:FacetProperty a rdfs:Class;
+ rdfs:subClassOf rdf:Property;
+ skos:definition """A facet property is a property that can be used for
+ faceted search."""@en.
+
:VirtualProperty a rdfs:Class;
rdfs:subClassOf rdf:Property;
skos:definition """A virtual property is a property whose value can be