Revision: 14468
http://gate.svn.sourceforge.net/gate/?rev=14468&view=rev
Author: valyt
Date: 2011-11-01 09:38:06 +0000 (Tue, 01 Nov 2011)
Log Message:
-----------
Potentially working support for indexing document features (waiting on another
change before we can test it).
Modified Paths:
--------------
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/SesameSemanticAnnotationHelper.java
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/URICache.java
Modified:
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/SesameSemanticAnnotationHelper.java
===================================================================
---
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/SesameSemanticAnnotationHelper.java
2011-11-01 02:27:39 UTC (rev 14467)
+++
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/SesameSemanticAnnotationHelper.java
2011-11-01 09:38:06 UTC (rev 14468)
@@ -83,11 +83,14 @@
import org.openrdf.rio.Rio;
import gate.Annotation;
+import gate.Document;
+import gate.FeatureMap;
import gate.Gate;
import gate.mimir.AbstractSemanticAnnotationHelper;
import gate.mimir.Constraint;
import gate.mimir.ConstraintType;
import gate.mimir.IndexConfig;
+import gate.mimir.SemanticAnnotationHelper;
import gate.mimir.index.IndexException;
import gate.mimir.index.Indexer;
import gate.mimir.index.Mention;
@@ -230,6 +233,14 @@
private static NumberFormat percentFormat;
+
+ /**
+ * When in document mode (see
+ * {@link SemanticAnnotationHelper#isInDocumentMode()}), stores the
features
+ * for the current document.
+ */
+ private transient FeatureMap documentFeatures;
+
protected ValueFactory factory;
private URICache uriCache;
@@ -378,14 +389,35 @@
}
}
- @Override
- public String[] getMentionUris(Annotation annotation, int length,
+ @Override
+ public void documentStart(Document document) {
+ if(isInDocumentMode()) {
+ documentFeatures = document.getFeatures();
+ }
+ }
+
+ @Override
+ public void documentEnd() {
+ documentFeatures = null;
+ }
+
+ @Override
+ public String[] getMentionUris(Annotation ann, int length,
Indexer indexer) {
if (!initDone) {
init(indexer);
}
+
+ FeatureMap featuresToIndex;
+ if(isInDocumentMode()) {
+ length = -1;
+ featuresToIndex = documentFeatures;
+ } else {
+ featuresToIndex = ann.getFeatures();
+ }
+
try {
- URI[] mentionURIs = uriCache.getMentionURIs(annotation,
length);
+ URI[] mentionURIs =
uriCache.getMentionURIs(featuresToIndex, length);
String[] res = new String[mentionURIs.length];
for (int i = 0; i < mentionURIs.length; i++) {
res[i] = mentionURIs[i].stringValue();
@@ -539,8 +571,9 @@
BindingSet binding = result.next();
String mentionURI =
binding.getBinding("mentionInstance")
.getValue().stringValue();
- mentions.add(new Mention(mentionURI, ((Literal)
binding
-
.getBinding("length").getValue()).intValue()));
+ int length = isInDocumentMode()?
Mention.NO_LENGTH :
+ ((Literal)
binding.getBinding("length").getValue()).intValue();
+ mentions.add(new Mention(mentionURI, length));
}
return mentions;
} catch (MalformedQueryException e) {
@@ -635,8 +668,7 @@
.get(SESAME_RMANAGER_KEY);
String repositoryName = (String) config.getContext().get(
SESAME_REPOSITORY_NAME_KEY);
- if (repositoryName == null)
- repositoryName = "owlim";
+ if (repositoryName == null) repositoryName = "owlim";
if (manager == null) {
// not initialised yet - > we create it and save it
ourselves.
File topDir = config.getIndexDirectory();
Modified: mimir/trunk/plugins/sesame/src/gate/mimir/sesame/URICache.java
===================================================================
--- mimir/trunk/plugins/sesame/src/gate/mimir/sesame/URICache.java
2011-11-01 02:27:39 UTC (rev 14467)
+++ mimir/trunk/plugins/sesame/src/gate/mimir/sesame/URICache.java
2011-11-01 09:38:06 UTC (rev 14468)
@@ -247,11 +247,10 @@
* caching.
*/
protected class NonNominalFeatureValues {
- public NonNominalFeatureValues(Annotation annotation,
+ public NonNominalFeatureValues(FeatureMap features,
ValueFactory factory) {
hasNonNominalFeatures = false;
numericValues = new
double[owner.getFloatFeatureNames().length];
- FeatureMap features = annotation.getFeatures();
for (int i = 0; i <
owner.getFloatFeatureNames().length; i++) {
Object value =
features.get(owner.getFloatFeatureNames()[i]);
double valueNum = MIMIR_NULL_DOUBLE;
@@ -711,13 +710,13 @@
* @return an array of 2 URI values, the first being the top level
template,
* the second being the specialised template.
*/
- public URI[] getMentionURIs(Annotation annotation, int length) {
+ public URI[] getMentionURIs(FeatureMap features, int length) {
URI topLevelTemplateInstance = null;
URI specialisedInstance = null;
// extract the nominal values
String[] nominalValues = new
String[owner.getNominalFeatureNames().length];
for (int i = 0; i < owner.getNominalFeatureNames().length; i++)
{
- Object value = annotation.getFeatures().get(
+ Object value = features.get(
owner.getNominalFeatureNames()[i]);
if (value == null) {
nominalValues[i] = MIMIR_NULL_STRING;
@@ -779,7 +778,7 @@
topLevelTemplateInstance = topLevel.uri;
// now see if we need the specialise
NonNominalFeatureValues nonNomvalues = new
NonNominalFeatureValues(
- annotation, owner.factory);
+ features, owner.factory);
if (nonNomvalues.hasNonNominalFeatures) {
specialisedInstance = topLevel.map.get(nonNomvalues);
if (specialisedInstance == null) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
RSA® Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs