Author: ito
Date: Sat May 7 08:34:39 2011
New Revision: 1100479
URL: http://svn.apache.org/viewvc?rev=1100479&view=rev
Log:
CLEREZZA-501: reindex thread improved and indexing urirefs implemented
Modified:
incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/LuceneTools.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
Modified:
incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java?rev=1100479&r1=1100478&r2=1100479&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java
Sat May 7 08:34:39 2011
@@ -22,7 +22,7 @@ import java.io.IOException;
import java.util.List;
import java.util.concurrent.locks.Lock;
import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
-import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.NonLiteral;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.access.LockableMGraph;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
@@ -92,7 +92,7 @@ public class IndexService extends Resour
}
@Override
- public List<Resource> findResources(List<Condition> conditions) {
+ public List<NonLiteral> findResources(List<Condition> conditions) {
try {
return graphIndexer.findResources(conditions);
} catch (ParseException ex) {
@@ -101,7 +101,7 @@ public class IndexService extends Resour
}
@Override
- public List<Resource> findResources(UriRef uriRef, String pattern) {
+ public List<NonLiteral> findResources(UriRef uriRef, String pattern) {
try {
return graphIndexer.findResources(uriRef, pattern);
} catch (ParseException ex) {
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java?rev=1100479&r1=1100478&r2=1100479&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
Sat May 7 08:34:39 2011
@@ -19,10 +19,7 @@
package org.apache.clerezza.rdf.cris;
import java.io.IOException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -30,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import org.apache.clerezza.rdf.core.NonLiteral;
import org.apache.clerezza.rdf.core.Resource;
import org.apache.clerezza.rdf.core.Triple;
@@ -63,7 +61,7 @@ import org.slf4j.LoggerFactory;
/**
*
- * @author tio
+ * @author tio, daniel
*/
public class GraphIndexer extends ResourceFinder {
@@ -82,59 +80,164 @@ public class GraphIndexer extends Resour
private final GraphListener listener1;
private final GraphListener listener2;
-
- //TODO
+ /**
+ * When resources are added to or deleted from the base graph,
+ * this thread updates the Lucene index asynchronously.
+ */
class ReindexThread extends Thread {
- Set<Resource> resourcesToProcess;
- boolean stop = false;
-
- ReindexThread() {
- resourcesToProcess = Collections.synchronizedSet(new
HashSet<Resource>());
- }
-
+ //TODO: would this measure be better as a time unit??
+ private final long resourceCacheCapacity;
+ private long counter;
+ private final String name;
+ private final long stableThreshold;
+ private final Set<Resource> resourcesToProcess;
+ private boolean stop;
+ private boolean resourcesClean;
+ private final Lock lock = new ReentrantLock(true);
+ private final java.util.concurrent.locks.Condition
indexResources =
+ lock.newCondition();
+
+ /**
+ * Constructs a new thread with specified name and indexing
threshold.
+ * Setting the name may be useful for distinguishing logging
output when
+ * multiple instances of GraphIndexer are running.
+ *
+ * {@code stableThreshold} specifies a waiting period before
the
+ * indexing starts. The timer is restarted if more resources
are added
+ * within {@code stableThreshold} nanoseconds. A high value
means the
+ * thread will wait a long time before indexing resources added
using
+ * {@link addResource(Resource resource)}. A short value means
new
+ * resources are added to the index quickly. Configure this
value such
+ * that when adding many new resources in a short time these
are
+ * gathered and indexed at once.
+ *
+ * @param name the thread name (used in logging output).
+ * @param stableThreshold
+ * If no new resource has been added for {@code
stableThreshold}
+ * nanoseconds and there are cached unindexed
resources, then
+ * indexing starts.
+ * @param resourceCacheCapacity
+ * How many resources will be cached maximally
before indexing.
+ * A negative number means infinite.
+ */
+ ReindexThread(String name, long stableThreshold, long
resourceCacheCapacity) {
+ this.resourceCacheCapacity = resourceCacheCapacity;
+ this.stableThreshold = stableThreshold;
+ this.name = name;
+ this.resourcesToProcess = new HashSet<Resource>();
+ this.resourcesClean = true;
+ }
+
+ /**
+ * Constructs a new thread with specified indexing threshold.
+ *
+ * @code stableThreshold} specifies a waiting period before the
+ * indexing starts. The timer is restarted if more resources
are added
+ * within {@code stableThreshold} nanoseconds. A high value
means the
+ * thread will wait a long time before indexing resources added
using
+ * {@link addResource(Resource resource)}. A short value means
new
+ * resources are added to the index quickly. Configure this
value such
+ * that when adding many new resources in a short time these
are
+ * gathered and indexed at once.
+ *
+ * @param stableThreshold
+ * If no new resource has been added for {@code
stableThreshold}
+ * nanoseconds and there are cached unindexed
resources, then
+ * indexing starts.
+ * @param resourceCacheCapacity
+ * How many resources will be cached maximally
before indexing.
+ * A negative number means infinite.
+ */
+ ReindexThread(long stableThreshold, long resourceCacheCapacity)
{
+ this(null, stableThreshold, resourceCacheCapacity);
+ }
+
+
+ /**
+ * Request the termination of this thread. The thread will
finish its
+ * current operations before it terminates.
+ */
void stopThread() {
stop = true;
+ lock.lock();
+ try {
+ indexResources.signal();
+ } finally {
+ lock.unlock();
+ }
}
@Override
public void run() {
- final ReindexThread that = this;
- AccessController.doPrivileged(new PrivilegedAction() {
-
- @Override
- public Object run() {
- while (!stop) {
-// System.out.println("THREAD
running");
- try {
- if
(resourcesToProcess.size() < 50) {
- sleep(100);
- }
- } catch (InterruptedException
ex) {
-
logger.warn("ReindexThread interrupted while sleeping.");
- }
- if(resourcesToProcess.size() >
0) {
- //IMO the following 2
code lines should be synchronized
- Set<Resource> set;
- synchronized(that) {
- set = new
HashSet<Resource>(resourcesToProcess);
-
resourcesToProcess.clear();
- }
- for (Resource resource
: set) {
-
logger.info("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE" + resource);
-
indexResource(resource, luceneTools.getIndexWriter());
- }
-
luceneTools.commitChanges();
-
+ if(name == null) {
+ setName("CRIS Reindex Thread[" + getId() + "]");
+ } else {
+ setName(name);
+ }
+ stop = false;
+ counter = 0;
+ Set<Resource> set;
+ logger.info("{} started.", getName());
+ while (true) {
+ try {
+ lock.lock();
+ try {
+ waitForDirty();
+ if (stop) {
+ break;
}
+ logger.info("{}: registered
write - waiting for more writes to follow.", getName());
+ waitUntilStable();
+ set = new
HashSet<Resource>(resourcesToProcess);
+ resourcesToProcess.clear();
+ counter = 0;
+ resourcesClean = true;
+ } finally {
+ lock.unlock();
+ }
+ logger.info("{}: cache full or writes
have seized. Indexing...", getName());
+ for (Resource resource : set) {
+ indexResource(resource,
luceneTools.getIndexWriter());
}
- return null;
+ luceneTools.commitChanges();
+ } catch (InterruptedException ex) {
+ logger.warn("{}: interrupted: {}.",
getName(), ex);
+ }
+ }
+ logger.info("{} stopped.", getName());
+ }
+
+ private void waitUntilStable() throws InterruptedException {
+ while (!resourcesClean) {
+ resourcesClean = true;
+ indexResources.awaitNanos(stableThreshold);
+ if(++counter > resourceCacheCapacity) {
+ break;
}
- });
+ }
}
- public synchronized void addResource(Resource resource) {
- resourcesToProcess.add(resource);
+ private void waitForDirty() throws InterruptedException {
+ while (resourcesClean && !stop) {
+ indexResources.await();
+ }
+ }
+
+ /**
+ * Add a new resource for indexing.
+ *
+ * @param resource the resource.
+ */
+ public void addResource(Resource resource) {
+ lock.lock();
+ try {
+ resourcesToProcess.add(resource);
+ resourcesClean = false;
+ indexResources.signal();
+ } finally {
+ lock.unlock();
+ }
}
}
@@ -151,7 +254,7 @@ public class GraphIndexer extends Resour
luceneTools = new LuceneTools(this.currentIndex, analyzer);
processDefinitions();
- this.reindexer = new ReindexThread();
+ this.reindexer = new ReindexThread(100000000L, 500000L);
//TODO: find good values, make them configurable
//TODO
//reindexer.setDaemon(true);
@@ -159,7 +262,6 @@ public class GraphIndexer extends Resour
@Override
public void graphChanged(List<GraphEvent> events) {
- System.out.println("LALALALLALALALALLALA");
for (GraphEvent e : events) {
Triple triple = e.getTriple();
logger.debug("processing addition of
type " + triple.getObject());
@@ -178,18 +280,17 @@ public class GraphIndexer extends Resour
@Override
public void graphChanged(List<GraphEvent> events) {
- System.out.println("LALALALLALALALALLALA2");
for (GraphEvent e : events) {
- logger.info("Triple: " + e.getTriple());
+// logger.info("Triple: " + e.getTriple());
Triple triple = e.getTriple();
UriRef predicate =
triple.getPredicate();
Set<VirtualProperty> vProperties =
property2IncludingVProperty.get(predicate);
List<Resource> indexedResources = new
ArrayList<Resource>();
- logger.info("Predicate: " + predicate);
+// logger.info("Predicate: " + predicate);
for (VirtualProperty vProperty :
vProperties) {
- logger.info("Subject: " + " " +
triple.getSubject());
+// logger.info("Subject: " + " " +
triple.getSubject());
followInversePaths(triple.getSubject(),
vProperty.pathToIndexedResource(predicate), indexedResources);
}
@@ -219,19 +320,16 @@ public class GraphIndexer extends Resour
@Override
public boolean match(Triple triple) {
- System.out.println("MATCH START");
UriRef predicate = triple.getPredicate();
//check indirectly involved properties
Set<VirtualProperty> vProperties =
property2IncludingVProperty.get(predicate);
if (vProperties != null) {
for (VirtualProperty vProperty :
vProperties) {
if
(property2TypeMap.containsKey(vProperty)) {
-
System.out.println("MATCH TRUE");
return true;
}
}
}
- System.out.println("MATCH FALSE");
return false;
}
});
@@ -391,7 +489,7 @@ public class GraphIndexer extends Resour
List<NonLiteral> instances = new ArrayList<NonLiteral>();
for (UriRef indexedType : type2IndexedProperties.keySet()) {
- //TODO lock necessary
+ //lock necessary?
Lock lock = new GraphNode(indexedType,
this.baseGraph).readLock();
lock.lock();
try {
@@ -404,7 +502,6 @@ public class GraphIndexer extends Resour
}
}
logger.debug("instances " + instances.size());
- //val writer = new IndexWriter(index, analyzer, true,
IndexWriter.MaxFieldLength.UNLIMITED);
IndexWriter writer = luceneTools.getIndexWriter(true);
for (NonLiteral instance : instances) {
indexResource(instance, writer);
@@ -413,7 +510,7 @@ public class GraphIndexer extends Resour
}
@Override
- public List<Resource> findResources(List<Condition> conditions)
+ public List<NonLiteral> findResources(List<Condition> conditions)
throws ParseException {
BooleanQuery booleanQuery = new BooleanQuery();
@@ -441,9 +538,8 @@ public class GraphIndexer extends Resour
} catch (IOException ex) {
}
ScoreDoc[] hits = collector.topDocs().scoreDocs;
- //logger.debug("Found " + hits.length + " hits for "+pattern);
- List<Resource> result = new ArrayList<Resource>();
+ List<NonLiteral> result = new ArrayList<NonLiteral>();
for (ScoreDoc hit : hits) {
int docId = hit.doc;
Document d;
@@ -458,12 +554,12 @@ public class GraphIndexer extends Resour
return result;
}
- private Resource getResource(Document d) {
+ private NonLiteral getResource(Document d) {
return new UriRef(d.get(URI_FIELD_NAME));
}
@Override
- public List<Resource> findResources(UriRef property, String pattern)
+ public List<NonLiteral> findResources(UriRef property, String pattern)
throws ParseException {
List<Condition> list = new ArrayList<Condition>();
list.add(new WildcardCondition(new PropertyHolder(property),
pattern));
@@ -484,14 +580,14 @@ public class GraphIndexer extends Resour
private void indexNamedResource(UriRef uriRef, IndexWriter writer)
throws IOException {
//val searcher = new IndexSearcher(index, true);
- IndexSearcher searcher = luceneTools.getIndexSearcher();
+ //IndexSearcher searcher = luceneTools.getIndexSearcher();
Term term = new Term(URI_FIELD_NAME, uriRef.getUnicodeString());
writer.deleteDocuments(term);
//the reindexing might be caused by the removal of a type
statement
GraphNode node = new GraphNode(uriRef, this.baseGraph);
List<UriRef> types = new ArrayList<UriRef>();
- //TODO lock necessary
+ //lock necessary?
Lock lock = node.readLock();
lock.lock();
try {
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java?rev=1100479&r1=1100478&r2=1100479&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/JoinVirtualProperty.java
Sat May 7 08:34:39 2011
@@ -58,6 +58,9 @@ public class JoinVirtualProperty extends
builder.append(" ");
}
}
+ if(builder.length() == 0) {
+ return "";
+ }
return builder.deleteCharAt(builder.length() -1 ).toString();
}
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/LuceneTools.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/LuceneTools.java?rev=1100479&r1=1100478&r2=1100479&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/LuceneTools.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/LuceneTools.java
Sat May 7 08:34:39 2011
@@ -77,7 +77,6 @@ public class LuceneTools {
public void close() throws CorruptIndexException, IOException {
super.close();
invokeClose = false;
- indexWriter = null;
}
}
@@ -137,6 +136,7 @@ public class LuceneTools {
}
try {
if(luceneIndexDir != null) {
+ System.out.println("OPENING NEW DIR IN GET
INDEXWRITER");
indexDirectory =
FSDirectory.open(luceneIndexDir);
}
/*boolean createDir = false;
@@ -180,16 +180,19 @@ public class LuceneTools {
*
*/
public void closeIndexWriter() {
- System.out.println("H--------------------------------");
+ System.out.println("Closing IndexWriter");
try {
if(indexWriter != null) {
//TODO do this in an extra thread, execution
time configurable
//call optimize only when necessary
- if(!indexWriter.getReader().isOptimized()) {
-
System.out.println("E--------------------------------");
- indexWriter.optimize();
+ try {
+
if(!indexWriter.getReader().isOptimized()) {
+ System.out.println("Optimizing
IndexWriter");
+ indexWriter.optimize();
+ }
+ } finally {
+ indexWriter.close();
}
- indexWriter.close();
}
} catch (IOException ex) {
logger.error(ex.getMessage());
@@ -209,12 +212,15 @@ public class LuceneTools {
public IndexSearcher getIndexSearcher() throws RuntimeException {
try {
if (indexSearcher != null &&
indexSearcher.getIndexReader().isCurrent()) {
+ System.out.println("RETURNING EXISTING
INDEXSEARCHER");
return indexSearcher;
}
- if(luceneIndexDir != null) {
- indexDirectory =
FSDirectory.open(luceneIndexDir);
- }
+// if(luceneIndexDir != null) {
+// System.out.println("OPENING NEW DIR!!");
+// indexDirectory =
FSDirectory.open(luceneIndexDir);
+// }
if (IndexReader.indexExists(indexDirectory)) {
+ System.out.println("OPENING NEW INDEXSEARCHER");
indexSearcher = new
IndexSearcher(indexDirectory, true);
return indexSearcher;
}
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java?rev=1100479&r1=1100478&r2=1100479&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
Sat May 7 08:34:39 2011
@@ -25,11 +25,18 @@ import java.util.Iterator;
import java.util.List;
import java.util.concurrent.locks.Lock;
import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.Resource;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.utils.GraphNode;
+import org.apache.clerezza.utils.UriException;
+import org.apache.clerezza.utils.UriUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class PropertyHolder extends VirtualProperty {
-
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
UriRef property;
public PropertyHolder(UriRef property) {
@@ -46,9 +53,18 @@ public class PropertyHolder extends Virt
Lock lock = node.readLock();
lock.lock();
try {
- Iterator<Literal> iter =
node.getLiterals(this.property);
+ Iterator<Resource> iter =
node.getObjects(this.property);
while(iter.hasNext()) {
- list.add(iter.next().getLexicalForm());
+ Resource resource = iter.next();
+ if(resource instanceof Literal) {
+
list.add(((Literal)resource).getLexicalForm());
+ } else if(resource instanceof UriRef) {
+ try {
+
list.add(UriUtil.encodeAll(((UriRef) resource).getUnicodeString()));
+ } catch (UriException ex) {
+ logger.error("Could not encode
UriRef: " + ex.getMessage());
+ }
+ }
}
} finally {
lock.unlock();
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java?rev=1100479&r1=1100478&r2=1100479&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
Sat May 7 08:34:39 2011
@@ -21,7 +21,7 @@ package org.apache.clerezza.rdf.cris;
import java.util.ArrayList;
import java.util.List;
-import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.NonLiteral;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
@@ -48,14 +48,14 @@ import org.apache.lucene.search.Wildcard
/**
* find resources matching the specified condition
*/
- public abstract List<Resource> findResources(List<Condition>
conditions) throws ParseException;
+ public abstract List<NonLiteral> findResources(List<Condition>
conditions) throws ParseException;
/**
* Find resource with a properties whose value matches a pattern
*/
- public abstract List<Resource> findResources(UriRef property, String
pattern) throws ParseException ;
+ public abstract List<NonLiteral> findResources(UriRef property, String
pattern) throws ParseException ;
- public List<Resource> findResources(VirtualProperty property,String
pattern) throws ParseException {
+ public List<NonLiteral> findResources(VirtualProperty property,String
pattern) throws ParseException {
//TODO?
Query query = new WildcardQuery(new Term(property.stringKey,
pattern));
List<Condition> list = new ArrayList<Condition>();
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java?rev=1100479&r1=1100478&r2=1100479&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
Sat May 7 08:34:39 2011
@@ -16,8 +16,11 @@
*/
package org.apache.clerezza.rdf.cris;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.clerezza.rdf.cris.ontologies.CRIS;
import org.apache.clerezza.rdf.core.*;
import org.apache.clerezza.rdf.core.impl.*;
@@ -25,6 +28,8 @@ import org.apache.clerezza.rdf.utils.*;
import org.apache.clerezza.rdf.ontologies.FOAF;
import org.apache.clerezza.rdf.ontologies.RDF;
import org.apache.clerezza.rdf.ontologies.RDFS;
+import org.apache.clerezza.utils.UriException;
+import org.apache.clerezza.utils.UriUtil;
import org.apache.lucene.queryParser.ParseException;
import org.wymiwyg.commons.util.Util;
import org.junit.*;
@@ -66,8 +71,14 @@ public class GraphIndexerTest {
List<UriRef> list = new ArrayList<UriRef>();
list.add(FOAF.firstName);
list.add(FOAF.lastName);
+ list.add(FOAF.homepage);
createDefinition(FOAF.Person, list);
service = new GraphIndexer(definitions, dataGraph);
+
+ GraphNode nodeB = new GraphNode(new UriRef(Util.createURN5()),
dataGraph);
+ nodeB.addProperty(RDF.type, FOAF.Person);
+ nodeB.addProperty(FOAF.homepage, new
UriRef("http://myhomepage/foo?query=bla&bla=test"));
+
createPerson("John", "Doe");
createPerson("Jane", "Doe");
createPerson("Frank", "Capra");
@@ -93,8 +104,24 @@ public class GraphIndexerTest {
}
@Test
+ public void findUriOfResources() throws ParseException,
InterruptedException {
+ List<NonLiteral> results;
+ //TODO
+ Thread.sleep(1000);
+
+ try {
+ String encodedUri =
UriUtil.encodeAll("p://myhomepage/foo?query=bla&bla=te");
+ results = service.findResources(FOAF.homepage, "*" +
encodedUri + "*");
+ Assert.assertEquals(1, results.size());
+ } catch (UriException ex) {
+
+ }
+
+ }
+
+ @Test
public void findResources() throws ParseException, InterruptedException
{
- List<Resource> results;
+ List<NonLiteral> results;
//TODO
Thread.sleep(1000);
results = service.findResources(FOAF.firstName, "*Joe*");
@@ -110,7 +137,7 @@ public class GraphIndexerTest {
conditions.add(new WildcardCondition(FOAF.lastName,
"*Wotsit*"));
//TODO
Thread.sleep(1000);
- List<Resource> results =
service.findResources(conditions);
+ List<NonLiteral> results =
service.findResources(conditions);
Assert.assertEquals(1, results.size());
}
@@ -122,7 +149,7 @@ public class GraphIndexerTest {
conditions.add(new WildcardCondition(FOAF.firstName,
"*Wil*"));
//TODO
Thread.sleep(1000);
- List<Resource> results =
service.findResources(conditions);
+ List<NonLiteral> results =
service.findResources(conditions);
Assert.assertEquals(1, results.size());
} catch (ParseException ex) {
@@ -134,7 +161,7 @@ public class GraphIndexerTest {
try {
createPerson("Another Joe", "Simpsons");
Thread.sleep(1000);
- List<Resource> results =
service.findResources(FOAF.firstName, "*Joe*");
+ List<NonLiteral> results =
service.findResources(FOAF.firstName, "*Joe*");
Assert.assertEquals(3, results.size());
} catch (InterruptedException ex) {
} catch (ParseException ex) {
@@ -148,11 +175,11 @@ public class GraphIndexerTest {
node.addPropertyValue(FOAF.firstName, "Another Jane");
node.addPropertyValue(FOAF.lastName, "Samsing");
Thread.sleep(1000);
- List<Resource> results =
service.findResources(FOAF.firstName, "*Jane*");
+ List<NonLiteral> results =
service.findResources(FOAF.firstName, "*Jane*");
Assert.assertEquals(2, results.size());
node.addProperty(RDF.type, FOAF.Person);
Thread.sleep(1000);
- List<Resource> results2 =
service.findResources(FOAF.firstName, "*Jane*");
+ List<NonLiteral> results2 =
service.findResources(FOAF.firstName, "*Jane*");
Assert.assertEquals(3, results2.size());
}
@@ -165,11 +192,11 @@ public class GraphIndexerTest {
node.addPropertyValue(FOAF.lastName, "Samsing");
node.addProperty(RDF.type, FOAF.Person);
Thread.sleep(1000);
- List<Resource> results =
service.findResources(FOAF.firstName, "*Jane*");
+ List<NonLiteral> results =
service.findResources(FOAF.firstName, "*Jane*");
Assert.assertEquals(3, results.size());
node.deleteProperties(RDF.type);
Thread.sleep(1000);
- List<Resource> results2 =
service.findResources(FOAF.firstName, "*Jane*");
+ List<NonLiteral> results2 =
service.findResources(FOAF.firstName, "*Jane*");
Assert.assertEquals(2, results2.size());
} catch (ParseException ex) {
} catch (InterruptedException ex) {
@@ -184,11 +211,11 @@ public class GraphIndexerTest {
node.addPropertyValue(FOAF.lastName, "Samsing");
node.addProperty(RDF.type, FOAF.Person);
Thread.sleep(1000);
- List<Resource> results =
service.findResources(FOAF.firstName, "*Jane*");
+ List<NonLiteral> results =
service.findResources(FOAF.firstName, "*Jane*");
Assert.assertEquals(3, results.size());
node.deleteProperties(FOAF.firstName);
Thread.sleep(1000);
- List<Resource> results2 =
service.findResources(FOAF.firstName, "*Jane*");
+ List<NonLiteral> results2 =
service.findResources(FOAF.firstName, "*Jane*");
Assert.assertEquals(2, results2.size());
} catch (ParseException ex) {
} catch (InterruptedException ex) {
@@ -201,7 +228,7 @@ public class GraphIndexerTest {
service.reCreateIndex();
//the old data still available
Thread.sleep(1000);//TODO
- List<Resource> results =
service.findResources(FOAF.firstName, "*Joe*");
+ List<NonLiteral> results =
service.findResources(FOAF.firstName, "*Joe*");
Assert.assertEquals(2, results.size());
} catch (ParseException ex) {
}
@@ -225,7 +252,7 @@ public class GraphIndexerTest {
{
try {
//the old data still available
- List<Resource> results =
service.findResources(FOAF.firstName, "*Joe*");
+ List<NonLiteral> results =
service.findResources(FOAF.firstName, "*Joe*");
Assert.assertEquals(2, results.size());
} catch (ParseException ex) {
}
@@ -233,7 +260,7 @@ public class GraphIndexerTest {
{
try {
//the newly indexed property
- List<Resource> results =
service.findResources(RDFS.comment, "*two*");
+ List<NonLiteral> results =
service.findResources(RDFS.comment, "*two*");
Assert.assertEquals(1, results.size());
} catch (ParseException ex) {
}
@@ -256,13 +283,13 @@ public class GraphIndexerTest {
Thread.sleep(2000);
{
- List<Resource> results =
service.findResources(joinProperty, "*John*");
+ List<NonLiteral> results =
service.findResources(joinProperty, "*John*");
Assert.assertEquals(2, results.size());
}
{
- List<Resource> results =
service.findResources(joinProperty, "John Doe");
+ List<NonLiteral> results =
service.findResources(joinProperty, "John Doe");
Assert.assertEquals(1, results.size());
}
@@ -270,14 +297,14 @@ public class GraphIndexerTest {
//late addition
{
//check before
- List<Resource> results =
service.findResources(joinProperty, "*Joe*");
+ List<NonLiteral> results =
service.findResources(joinProperty, "*Joe*");
Assert.assertEquals(2, results.size());
}
createPerson("Another Joe", "Simpsons");
Thread.sleep(2000);
{
- List<Resource> results =
service.findResources(joinProperty, "*Joe*");
+ List<NonLiteral> results =
service.findResources(joinProperty, "*Joe*");
Assert.assertEquals(3, results.size());
}
@@ -304,7 +331,7 @@ public class GraphIndexerTest {
service.reCreateIndex();
Thread.sleep(1000);
{
- List<Resource> results =
service.findResources(pathProperty, "Silvio");
+ List<NonLiteral> results =
service.findResources(pathProperty, "Silvio");
Assert.assertEquals(1, results.size());
}
//and a late addtition, lets give Frank a pet
@@ -317,7 +344,7 @@ public class GraphIndexerTest {
//TODO
Thread.sleep(1000);
{
- List<Resource> results =
service.findResources(pathProperty, "Silvio");
+ List<NonLiteral> results =
service.findResources(pathProperty, "Silvio");
Assert.assertEquals(2, results.size());
}
//lets give that pet an additional name
@@ -325,7 +352,7 @@ public class GraphIndexerTest {
//TODO
Thread.sleep(1000);
{
- List<Resource> results =
service.findResources(pathProperty, "Fifi");
+ List<NonLiteral> results =
service.findResources(pathProperty, "Fifi");
Assert.assertEquals(1, results.size());
}
} catch (ParseException ex) {