From 9a8e4943ba87eae91bed6cb4ceb7cf38e01fd177 Mon Sep 17 00:00:00 2001 From: Fadi Maali Date: Mon, 24 Mar 2014 11:09:00 -0400 Subject: [PATCH] some further updates to make the extension compatible with ORefine 2.6 and updating the LARQ to JenaText --- module/scripts/rdf-schema-alignment.js | 9 ++- module/scripts/sparql-service-dialog.html | 2 +- .../grefine/reconcile/ServiceRegistry.java | 6 +- .../reconcile/commands/AddServiceCommand.java | 8 +-- .../UploadFileAndAddServiceCommand.java | 4 +- .../rdf/endpoints/QueryEndpointFactory.java | 4 +- .../rdf/executors/DumpQueryExecutor.java | 11 --- ...y.java => JenaTextSparqlQueryFactory.java} | 68 ++++++++++--------- .../factories/PlainSparqlQueryFactory.java | 2 +- .../reconcile/sindice/SindiceBroker.java | 4 +- 10 files changed, 58 insertions(+), 60 deletions(-) rename src/org/deri/grefine/reconcile/rdf/factories/{LarqSparqlQueryFactory.java => JenaTextSparqlQueryFactory.java} (83%) diff --git a/module/scripts/rdf-schema-alignment.js b/module/scripts/rdf-schema-alignment.js index 3ed7908..f329c6d 100644 --- a/module/scripts/rdf-schema-alignment.js +++ b/module/scripts/rdf-schema-alignment.js @@ -150,13 +150,20 @@ RdfSchemaAlignmentDialog.prototype._renderBody = function(body) { var self = this; $("#rdf-schema-alignment-tabs").tabs({ + activate:function(evt, tabs){ + if(tabs.newTab.index()===1){ + $("#rdf-schema-alignment-tabs-preview").css("display", ""); + self._previewRdf(); + } + }, select:function(evt,ui){ if(ui.index===1){ + $("#rdf-schema-alignment-tabs-preview").css("display", ""); self._previewRdf(); } } }); - $("#rdf-schema-alignment-tabs-preview").css("display", ""); + // // $("#rdf-schema-alignment-tabs-vocabulary-manager").css("display", ""); this._canvas = $(".schema-alignment-dialog-canvas"); diff --git a/module/scripts/sparql-service-dialog.html b/module/scripts/sparql-service-dialog.html index 1502975..81a63e2 100644 --- a/module/scripts/sparql-service-dialog.html +++ b/module/scripts/sparql-service-dialog.html @@ -34,7 +34,7 @@
This determines the syntax that will be used for search
diff --git a/src/org/deri/grefine/reconcile/ServiceRegistry.java b/src/org/deri/grefine/reconcile/ServiceRegistry.java index 2872851..152270d 100644 --- a/src/org/deri/grefine/reconcile/ServiceRegistry.java +++ b/src/org/deri/grefine/reconcile/ServiceRegistry.java @@ -33,7 +33,7 @@ import org.deri.grefine.reconcile.rdf.executors.RemoteQueryExecutor; import org.deri.grefine.reconcile.rdf.executors.VirtuosoRemoteQueryExecutor; import org.deri.grefine.reconcile.rdf.factories.BigOwlImSparqlQueryFactory; -import org.deri.grefine.reconcile.rdf.factories.LarqSparqlQueryFactory; +import org.deri.grefine.reconcile.rdf.factories.JenaTextSparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.PlainSparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.SparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.VirtuosoSparqlQueryFactory; @@ -267,8 +267,8 @@ private SparqlQueryFactory loadQueryFactoryFromJSON(JSONObject factoryObj) throw String type = factoryObj.getString("type"); if(type.equals("virtuoso")){ return new VirtuosoSparqlQueryFactory(); - }else if(type.equals("larq")){ - return new LarqSparqlQueryFactory(); + }else if(type.equals("jena-text")){ + return new JenaTextSparqlQueryFactory(); }else if(type.equals("bigowlim")){ return new BigOwlImSparqlQueryFactory(); }else{ diff --git a/src/org/deri/grefine/reconcile/commands/AddServiceCommand.java b/src/org/deri/grefine/reconcile/commands/AddServiceCommand.java index f999f4e..2cf8515 100644 --- a/src/org/deri/grefine/reconcile/commands/AddServiceCommand.java +++ b/src/org/deri/grefine/reconcile/commands/AddServiceCommand.java @@ -20,7 +20,7 @@ import org.deri.grefine.reconcile.rdf.executors.RemoteQueryExecutor; import org.deri.grefine.reconcile.rdf.executors.VirtuosoRemoteQueryExecutor; import org.deri.grefine.reconcile.rdf.factories.BigOwlImSparqlQueryFactory; -import org.deri.grefine.reconcile.rdf.factories.LarqSparqlQueryFactory; +import org.deri.grefine.reconcile.rdf.factories.JenaTextSparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.PlainSparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.SparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.VirtuosoSparqlQueryFactory; @@ -78,7 +78,7 @@ private ReconciliationService getRdfService(String name, String id, String url,S }else{ queryExecutor = new DumpQueryExecutor(model); } - SparqlQueryFactory queryFactory = new LarqSparqlQueryFactory(); + SparqlQueryFactory queryFactory = new JenaTextSparqlQueryFactory(); QueryEndpoint queryEndpoint = new QueryEndpointImpl(queryFactory, queryExecutor); return new RdfReconciliationService(id, name, queryEndpoint, DEFAULT_MATCH_THRESHOLD); } @@ -89,8 +89,8 @@ private ReconciliationService getSparqlService(String name, String id,String url graph = graph==null || graph.trim().isEmpty()?null:graph; QueryEndpoint queryEndpoint; - if(type.equals("larq")){ - SparqlQueryFactory queryFactory = new LarqSparqlQueryFactory(); + if(type.equals("jena-text")){ + SparqlQueryFactory queryFactory = new JenaTextSparqlQueryFactory(); QueryExecutor queryExecutor = new RemoteQueryExecutor(url, graph); queryEndpoint = new QueryEndpointImpl(queryFactory, queryExecutor); }else if(type.equals("virtuoso")){ diff --git a/src/org/deri/grefine/reconcile/commands/UploadFileAndAddServiceCommand.java b/src/org/deri/grefine/reconcile/commands/UploadFileAndAddServiceCommand.java index d134658..2d42a35 100644 --- a/src/org/deri/grefine/reconcile/commands/UploadFileAndAddServiceCommand.java +++ b/src/org/deri/grefine/reconcile/commands/UploadFileAndAddServiceCommand.java @@ -23,7 +23,7 @@ import org.deri.grefine.reconcile.rdf.endpoints.QueryEndpointImpl; import org.deri.grefine.reconcile.rdf.executors.DumpQueryExecutor; import org.deri.grefine.reconcile.rdf.executors.QueryExecutor; -import org.deri.grefine.reconcile.rdf.factories.LarqSparqlQueryFactory; +import org.deri.grefine.reconcile.rdf.factories.JenaTextSparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.SparqlQueryFactory; import org.json.JSONException; @@ -105,7 +105,7 @@ protected ReconciliationService getReconciliationService(HttpServletRequest requ throw new RuntimeException("name and at least one label property ar needed"); } - SparqlQueryFactory queryFactory = new LarqSparqlQueryFactory(); + SparqlQueryFactory queryFactory = new JenaTextSparqlQueryFactory(); QueryExecutor queryExecutor; if(propUris.size()==1){ queryExecutor = new DumpQueryExecutor(model,propUris.get(0)); diff --git a/src/org/deri/grefine/reconcile/rdf/endpoints/QueryEndpointFactory.java b/src/org/deri/grefine/reconcile/rdf/endpoints/QueryEndpointFactory.java index 86371eb..c07b76a 100644 --- a/src/org/deri/grefine/reconcile/rdf/endpoints/QueryEndpointFactory.java +++ b/src/org/deri/grefine/reconcile/rdf/endpoints/QueryEndpointFactory.java @@ -2,7 +2,7 @@ import org.deri.grefine.reconcile.rdf.executors.DumpQueryExecutor; import org.deri.grefine.reconcile.rdf.executors.QueryExecutor; -import org.deri.grefine.reconcile.rdf.factories.LarqSparqlQueryFactory; +import org.deri.grefine.reconcile.rdf.factories.JenaTextSparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.SparqlQueryFactory; import com.hp.hpl.jena.rdf.model.Model; @@ -10,7 +10,7 @@ public class QueryEndpointFactory { public QueryEndpoint getLarqQueryEndpoint(Model model){ - SparqlQueryFactory queryFactory = new LarqSparqlQueryFactory(); + SparqlQueryFactory queryFactory = new JenaTextSparqlQueryFactory(); QueryExecutor queryExecutor = new DumpQueryExecutor(model); return new QueryEndpointImpl(queryFactory, queryExecutor); } diff --git a/src/org/deri/grefine/reconcile/rdf/executors/DumpQueryExecutor.java b/src/org/deri/grefine/reconcile/rdf/executors/DumpQueryExecutor.java index ddb35d0..8df3940 100644 --- a/src/org/deri/grefine/reconcile/rdf/executors/DumpQueryExecutor.java +++ b/src/org/deri/grefine/reconcile/rdf/executors/DumpQueryExecutor.java @@ -17,7 +17,6 @@ import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.ReadWrite; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; @@ -53,16 +52,6 @@ public DumpQueryExecutor(Model m){ this(m,null,false,DEFAULT_MIN_NGRAM, DEFAULT_MAX_NGRAM); } - /*public DumpQueryExecutor(Model m, boolean ngramIndex,int minGram, int maxGram){ - loaded = true; - LARQ.setMinGram(minGram);LARQ.setMaxGram(maxGram); - this.model = m; - IndexBuilderString larqBuilder = new IndexBuilderString(ngramIndex?LARQ.NGRAM_INDEX:LARQ.STANDARD_INDEX) ; - larqBuilder.indexStatements(model.listStatements()) ; - larqBuilder.closeWriter() ; - this.index = larqBuilder.getIndex() ; - }*/ - public DumpQueryExecutor(Model m, String propertyUri, boolean ngramIndex,int minGram, int maxGram){ loaded = true; this.propertyUri = propertyUri; diff --git a/src/org/deri/grefine/reconcile/rdf/factories/LarqSparqlQueryFactory.java b/src/org/deri/grefine/reconcile/rdf/factories/JenaTextSparqlQueryFactory.java similarity index 83% rename from src/org/deri/grefine/reconcile/rdf/factories/LarqSparqlQueryFactory.java rename to src/org/deri/grefine/reconcile/rdf/factories/JenaTextSparqlQueryFactory.java index 0635edc..7b69ac6 100644 --- a/src/org/deri/grefine/reconcile/rdf/factories/LarqSparqlQueryFactory.java +++ b/src/org/deri/grefine/reconcile/rdf/factories/JenaTextSparqlQueryFactory.java @@ -23,11 +23,11 @@ * @author fadmaa * */ -public class LarqSparqlQueryFactory extends AbstractSparqlQueryFactory{ +public class JenaTextSparqlQueryFactory extends AbstractSparqlQueryFactory{ @Override public String getTypeSuggestSparqlQuery(String prefix, int limit) { - return SUGGEST_TYPE_QUERY_TEMPLATE.replace("[[QUERY]]", escapeQuery(prefix)).replace("[[LIMIT]]", String.valueOf(limit)); + return SUGGEST_TYPE_QUERY_TEMPLATE.replace("[[QUERY]]", escapeQuery(prefix)).replaceAll("\\[\\[LIMIT\\]\\]", String.valueOf(limit)); } /** @@ -74,6 +74,7 @@ private String getReconciliationSparqlQuery(String queryTemplate, ImmutableList< .replace(labelPlaceHolder, labelFilter) .replace("[[TYPE_FILTER]]", typesFilter) .replace("[[CONTEXT_FILTER]]", contextFilter) + .replace("[[LIMIT]]", String.valueOf(calculatedLimit)) .replace("[[LIMIT]]", String.valueOf(calculatedLimit)); } @@ -81,13 +82,13 @@ private String getReconciliationSparqlQuery(String queryTemplate, ImmutableList< @Override public String getPropertySuggestSparqlQuery(String prefix, String typeUri, int limit) { return SUGGEST_PROPERTY_WITH_SPECIFIC_SUBJECT_TYPE_QUERY_TEMPLATE.replaceAll("\\[\\[QUERY\\]\\]", escapeQuery(prefix)). - replace("[[LIMIT]]", String.valueOf(limit)) + replaceAll("\\[\\[LIMIT\\]\\]", String.valueOf(limit)) .replace("[[TYPE_URI]]", typeUri); } @Override public String getPropertySuggestSparqlQuery(String prefix, int limit) { - return SUGGEST_PROPERTY_QUERY_TEMPLATE.replaceAll("\\[\\[QUERY\\]\\]", prefix).replace("[[LIMIT]]", String.valueOf(limit)); + return SUGGEST_PROPERTY_QUERY_TEMPLATE.replaceAll("\\[\\[QUERY\\]\\]", prefix).replaceAll("\\[\\[LIMIT\\]\\]", String.valueOf(limit)); } @Override @@ -129,6 +130,7 @@ public String getEntitySearchSparqlQuery(String prefix, ImmutableList se int calculatedLimit = searchPropertyUris.size() * limit;//because we want the maximum possible number return SEARCH_ENTITY_QUERY_TEMPLATE.replace("[[QUERY]]", escapeQuery(prefix)) .replace("[[LABEL_PROPERTY_FILTER]]", labelFilter) + .replace("[[LIMIT]]",String.valueOf(calculatedLimit)) .replace("[[LIMIT]]",String.valueOf(calculatedLimit)); } @@ -176,62 +178,62 @@ public double getScore() { } private static final String SUGGEST_TYPE_QUERY_TEMPLATE = - "PREFIX pf: " + - "SELECT DISTINCT ?type ?label1 ?score1 ?label2 ?score2 " + + "PREFIX text: " + + "SELECT DISTINCT ?type ?label1 ?label2 " + "WHERE{" + "[] a ?type. " + "{" + - "OPTIONAL {?type ?label1. " + - "(?label1 ?score1) pf:textMatch '[[QUERY]]*'. }" + - "OPTIONAL {?type ?label2. " + - "(?label2 ?score2) pf:textMatch '[[QUERY]]*'. } " + + "OPTIONAL {?type (?label1 '[[QUERY]]*' [[LIMIT]] ) . " + + "?type ?label1 . }" + + "OPTIONAL {?type (?label2 '[[QUERY]]*' [[LIMIT]] )." + + "?type ?label2.} " + "FILTER (bound(?label1) || bound(?label2))" + "}" + - "} ORDER BY desc(?score1) LIMIT [[LIMIT]]"; + "} LIMIT [[LIMIT]]"; private static final String SUGGEST_PROPERTY_WITH_SPECIFIC_SUBJECT_TYPE_QUERY_TEMPLATE = - "PREFIX pf: " + - "SELECT DISTINCT ?p ?label1 ?score1 ?label2 ?score2 " + + "PREFIX text: " + + "SELECT DISTINCT ?p ?label1 ?label2 " + "WHERE{" + "[] a <[[TYPE_URI]]>; " + "?p ?v. " + "{" + - "OPTIONAL {?p ?label1. " + - "(?label1 ?score1) pf:textMatch '[[QUERY]]*'. }" + - "OPTIONAL {?p ?label2. " + - "(?label2 ?score2) pf:textMatch '[[QUERY]]*'. } " + + "OPTIONAL {?p (?label1 '[[QUERY]]*' [[LIMIT]]). " + + "?p ?label1. }" + + "OPTIONAL {?p (?label2 '[[QUERY]]*' [[LIMIT]]). " + + "?p ?label2. }" + "FILTER (bound(?label1) || bound(?label2))" + "}" + - "} ORDER BY desc(?score1) LIMIT [[LIMIT]]"; + "} LIMIT [[LIMIT]]"; private static final String SUGGEST_PROPERTY_QUERY_TEMPLATE = - "PREFIX pf: " + - "SELECT DISTINCT ?p ?label1 ?score1 ?label2 ?score2 " + + "PREFIX text: " + + "SELECT DISTINCT ?p ?label1 ?label2 " + "WHERE{" + "[] ?p ?v. " + "{" + - "OPTIONAL {?p ?label1. " + - "(?label1 ?score1) pf:textMatch '[[QUERY]]*'. }" + - "OPTIONAL {?p ?label2. " + - "(?label2 ?score2) pf:textMatch '[[QUERY]]*'. } " + + "OPTIONAL {?p (?label1 '[[QUERY]]*' [[LIMIT]]). " + + "?p ?label1. }" + + "OPTIONAL {?p (?label2 '[[QUERY]]*' [[LIMIT]]). " + + "?p ?label2. }" + "FILTER (bound(?label1) || bound(?label2))" + "}" + - "} ORDER BY desc(?score1) LIMIT [[LIMIT]]"; + "} LIMIT [[LIMIT]]"; private static final String RECONCILE_QUERY_TEMPLATE = "PREFIX rdfs: " + - "PREFIX pf: " + + "PREFIX text: " + "PREFIX rdf: "+ - "SELECT ?entity ?label (MAX(?score) AS ?score1) " + + "SELECT ?entity ?label " + "WHERE" + "{" + + "?entity ?p (?label '[[QUERY]]' [[LIMIT]])." + "?entity ?p ?label." + - "(?label ?score) pf:textMatch '[[QUERY]]'. " + "[[LABEL_PROPERTY_FILTER]]" + "[[TYPE_FILTER]]" + "[[CONTEXT_FILTER]]" + " FILTER (isIRI(?entity))}GROUP BY ?entity ?label " + - "ORDER BY DESC(?score1) LIMIT [[LIMIT]]"; + "LIMIT [[LIMIT]]"; private static final String SINGLE_LABEL_PROPERTY_RECONCILE_QUERY_TEMPLATE = "PREFIX rdfs: " + "PREFIX text: " + @@ -255,11 +257,11 @@ public double getScore() { "}GROUP BY ?entity LIMIT [[LIMIT]]"; private static final String SEARCH_ENTITY_QUERY_TEMPLATE = - "PREFIX pf: " + + "PREFIX text: " + "SELECT ?entity ?label " + "WHERE{" + - "?entity ?label_prop ?label. " + + "?entity ?label_prop (?label '[[QUERY]]*' [[LIMIT]]) . " + + "?entity ?label_prop ?label . " + "[[LABEL_PROPERTY_FILTER]]. " + - "(?label ?score1) pf:textMatch '[[QUERY]]*'. " + - "} ORDER BY desc(?score1) LIMIT [[LIMIT]]"; + "} LIMIT [[LIMIT]]"; } diff --git a/src/org/deri/grefine/reconcile/rdf/factories/PlainSparqlQueryFactory.java b/src/org/deri/grefine/reconcile/rdf/factories/PlainSparqlQueryFactory.java index 50eb9b2..a47ba49 100644 --- a/src/org/deri/grefine/reconcile/rdf/factories/PlainSparqlQueryFactory.java +++ b/src/org/deri/grefine/reconcile/rdf/factories/PlainSparqlQueryFactory.java @@ -11,7 +11,7 @@ import org.deri.grefine.reconcile.model.ReconciliationRequest; import org.deri.grefine.reconcile.model.SearchResultItem; import org.deri.grefine.reconcile.model.ReconciliationRequestContext.PropertyContext; -import org.deri.grefine.reconcile.rdf.factories.LarqSparqlQueryFactory.ScoredLabel; +import org.deri.grefine.reconcile.rdf.factories.JenaTextSparqlQueryFactory.ScoredLabel; import org.deri.grefine.reconcile.util.StringUtils; import org.json.JSONException; import org.json.JSONWriter; diff --git a/src/org/deri/grefine/reconcile/sindice/SindiceBroker.java b/src/org/deri/grefine/reconcile/sindice/SindiceBroker.java index f1d6046..d74c272 100644 --- a/src/org/deri/grefine/reconcile/sindice/SindiceBroker.java +++ b/src/org/deri/grefine/reconcile/sindice/SindiceBroker.java @@ -11,7 +11,7 @@ import java.util.List; -import org.deri.grefine.reconcile.rdf.factories.LarqSparqlQueryFactory; +import org.deri.grefine.reconcile.rdf.factories.JenaTextSparqlQueryFactory; import org.deri.grefine.reconcile.rdf.factories.SparqlQueryFactory; import org.deri.grefine.reconcile.util.GRefineJsonUtilities; import org.json.JSONArray; @@ -27,7 +27,7 @@ public class SindiceBroker { final static Logger logger = LoggerFactory.getLogger("SindiceBroker"); private final String sindiceSearchUrl = "http://api.sindice.com/v2/search"; - private SparqlQueryFactory queryFactory = new LarqSparqlQueryFactory(); + private SparqlQueryFactory queryFactory = new JenaTextSparqlQueryFactory(); public List guessDomain(String query, int limit, GRefineJsonUtilities jsonUtilities) { Model model;