Revision: 13744
http://gate.svn.sourceforge.net/gate/?rev=13744&view=rev
Author: valyt
Date: 2011-04-21 16:10:09 +0000 (Thu, 21 Apr 2011)
Log Message:
-----------
Tested: it works!
Modified Paths:
--------------
mimir/trunk/plugins/sparql/src/gate/mimir/sparql/SPARQLResultSet.java
mimir/trunk/plugins/sparql/src/gate/mimir/sparql/SPARQLSemanticAnnotationHelper.java
Modified: mimir/trunk/plugins/sparql/src/gate/mimir/sparql/SPARQLResultSet.java
===================================================================
--- mimir/trunk/plugins/sparql/src/gate/mimir/sparql/SPARQLResultSet.java
2011-04-21 15:28:19 UTC (rev 13743)
+++ mimir/trunk/plugins/sparql/src/gate/mimir/sparql/SPARQLResultSet.java
2011-04-21 16:10:09 UTC (rev 13744)
@@ -277,28 +277,19 @@
return str.toString();
}
- public static void main(String[] args) throws Exception{
- String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" +
- "PREFIX dbpedia: <http://dbpedia.org/resource/>\n" +
- "PREFIX dbp: <http://dbpedia.org/ontology/>\n" +
- "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" +
- "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
- "SELECT DISTINCT ?label ?inst ?cls\n" +
- " WHERE {\n" +
- " {\n" +
- " ?inst dbp:type dbpedia:Public_company .\n" +
- " ?inst foaf:name ?label .\n" +
- " FILTER (lang(?label) = \"en\")\n" +
- " ?inst a ?cls .\n" +
- " ?cls a owl:Class .\n" +
- " FILTER (?cls = dbp:Company)\n" +
- " }\n" +
- "}";
- SPARQLSemanticAnnotationHelper ssah = new SPARQLSemanticAnnotationHelper(
- "annType",
"http://localhost:8080/openrdf-workbench/repositories/DBPedia/query", new
String[]{},
- new String[]{}, new String[]{}, new String[]{}, new String[]{},
- null);
- System.out.println(ssah.runQuery(query));
- }
+// /**
+// * Test code.
+// * TODO: remove it
+// * @param args
+// * @throws Exception
+// */
+// public static void main(String[] args) throws Exception{
+// String query = "PREFIX :<http://dbpedia.org/ontology/> SELECT ?inst
WHERE { ?inst a ?class . FILTER (?class = :Mountain)} LIMIT 100";
+// SPARQLSemanticAnnotationHelper ssah = new SPARQLSemanticAnnotationHelper(
+// "annType",
"http://gateservice5:8081/openrdf-workbench/repositories/DBPedia/query", new
String[]{},
+// new String[]{}, new String[]{}, new String[]{}, new String[]{},
+// null);
+// System.out.println(ssah.runQuery(query));
+// }
}
Modified:
mimir/trunk/plugins/sparql/src/gate/mimir/sparql/SPARQLSemanticAnnotationHelper.java
===================================================================
---
mimir/trunk/plugins/sparql/src/gate/mimir/sparql/SPARQLSemanticAnnotationHelper.java
2011-04-21 15:28:19 UTC (rev 13743)
+++
mimir/trunk/plugins/sparql/src/gate/mimir/sparql/SPARQLSemanticAnnotationHelper.java
2011-04-21 16:10:09 UTC (rev 13744)
@@ -26,8 +26,10 @@
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.xml.stream.XMLInputFactory;
@@ -36,6 +38,7 @@
import org.apache.log4j.Logger;
+import gate.mimir.AbstractSemanticAnnotationHelper;
import gate.mimir.Constraint;
import gate.mimir.ConstraintType;
import gate.mimir.SemanticAnnotationHelper;
@@ -78,6 +81,23 @@
*/
public static final String SPARQL_QUERY_FEATURE_NAME = "sparql";
+
+ public static final String NOMINAL_FEATURES_KEY = "nominalFeatures";
+
+ public static final String INTEGER_FEATURES_KEY = "integerFeatures";
+
+ public static final String FLOAT_FEATURES_KEY = "floatFeatures";
+
+ public static final String TEXT_FEATURES_KEY = "textFeatures";
+
+ public static final String URI_FEATURES_KEY = "uriFeatures";
+
+ public static final String ANN_TYPE_KEY = "annotationType";
+
+ public static final String DELEGATE_KEY = "delegate";
+
+ public static final String SPARQL_ENDPOINT_KEY = "sparqlEndpoint";
+
/**
* The service endpoint where SPARQL queries are forwarded to.
*/
@@ -123,11 +143,46 @@
String[] integerFeatureNames, String[] floatFeatureNames,
String[] textFeatureNames, String[] uriFeatureNames,
SemanticAnnotationHelper delegate) {
- super(annotationType, nominalFeatureNames, integerFeatureNames,
+ super(annotationType,
+ concatenateArrays(nominalFeatureNames,
+ new String[]{SPARQL_QUERY_FEATURE_NAME}), integerFeatureNames,
floatFeatureNames, textFeatureNames, uriFeatureNames, delegate);
this.sparqlEndpoint = sparqlEndpoint;
}
+ public SPARQLSemanticAnnotationHelper(Map<String, Object> params) {
+ this((String)params.get(ANN_TYPE_KEY),
+ (String)params.get(SPARQL_ENDPOINT_KEY),
+ featureNames(params.get(NOMINAL_FEATURES_KEY)),
+ featureNames(params.get(INTEGER_FEATURES_KEY)),
+ featureNames(params.get(FLOAT_FEATURES_KEY)),
+ featureNames(params.get(TEXT_FEATURES_KEY)),
+ featureNames(params.get(URI_FEATURES_KEY)),
+ (SemanticAnnotationHelper)params.get(DELEGATE_KEY));
+ }
+
+ public SPARQLSemanticAnnotationHelper(String sparqlEndpoint,
+ AbstractSemanticAnnotationHelper delegate) {
+ this(delegate.getAnnotationType(),
+ sparqlEndpoint,
+ delegate.getNominalFeatureNames(),
+ delegate.getIntegerFeatureNames(),
+ delegate.getFloatFeatureNames(),
+ delegate.getTextFeatureNames(),
+ delegate.getUriFeatureNames(),
+ delegate);
+ }
+
+ protected static String[] featureNames(Object param) {
+ if(param == null) return null;
+ if(param instanceof String[]) return (String[])param;
+ if(param instanceof Collection) {
+ return ((Collection<String>)param).toArray(new
String[((Collection)param).size()]);
+ }
+ throw new IllegalArgumentException("Supplied parameter is neither a " +
+ "String array nor a String collection!");
+ }
+
@Override
public void init(QueryEngine queryEngine) {
super.init(queryEngine);
@@ -141,7 +196,7 @@
List<Constraint> passThroughConstraints = new ArrayList<Constraint>();
String query = null;
for(Constraint aConstraint : constraints) {
- if(aConstraint.getFeatureName() == SPARQL_QUERY_FEATURE_NAME) {
+ if(SPARQL_QUERY_FEATURE_NAME.equals(aConstraint.getFeatureName())) {
query = (queryPrefix != null ? queryPrefix : "") +
(String)aConstraint.getValue() +
(querySuffix != null ? querySuffix : "");
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs