Skip to content

Commit

Permalink
some further updates to make the extension compatible with ORefine 2.…
Browse files Browse the repository at this point in the history
…6 and updating the LARQ to JenaText
  • Loading branch information
fadmaa committed Mar 24, 2014
1 parent 67ed872 commit 9a8e494
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 60 deletions.
9 changes: 8 additions & 1 deletion module/scripts/rdf-schema-alignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion module/scripts/sparql-service-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<select id="endpoint-type" bind="endpoint_type">
<option value="plain">Generic SPARQL (poor performance)</option>
<option value="virtuoso">Virtuoso</option>
<option value="larq">LARQ (Lucene+ARQ)</option>
<option value="jena-text">Jena Text (Lucene+ARQ)</option>
<option value="bigowlim">BigOWLIM</option>
</select>
<div class="rdf-reconcile-field-details">This determines the syntax that will be used for search</div>
Expand Down
6 changes: 3 additions & 3 deletions src/org/deri/grefine/reconcile/ServiceRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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;

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -74,20 +74,21 @@ 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));

}

@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
Expand Down Expand Up @@ -129,6 +130,7 @@ public String getEntitySearchSparqlQuery(String prefix, ImmutableList<String> 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));
}

Expand Down Expand Up @@ -176,62 +178,62 @@ public double getScore() {
}

private static final String SUGGEST_TYPE_QUERY_TEMPLATE =
"PREFIX pf:<http://jena.hpl.hp.com/ARQ/property#> " +
"SELECT DISTINCT ?type ?label1 ?score1 ?label2 ?score2 " +
"PREFIX text:<http://jena.apache.org/text#> " +
"SELECT DISTINCT ?type ?label1 ?label2 " +
"WHERE{" +
"[] a ?type. " +
"{" +
"OPTIONAL {?type <http://www.w3.org/2000/01/rdf-schema#label> ?label1. " +
"(?label1 ?score1) pf:textMatch '[[QUERY]]*'. }" +
"OPTIONAL {?type <http://www.w3.org/2004/02/skos/core#prefLabel> ?label2. " +
"(?label2 ?score2) pf:textMatch '[[QUERY]]*'. } " +
"OPTIONAL {?type <http://www.w3.org/2000/01/rdf-schema#label> (?label1 '[[QUERY]]*' [[LIMIT]] ) . " +
"?type <http://www.w3.org/2000/01/rdf-schema#label> ?label1 . }" +
"OPTIONAL {?type <http://www.w3.org/2004/02/skos/core#prefLabel> (?label2 '[[QUERY]]*' [[LIMIT]] )." +
"?type <http://www.w3.org/2004/02/skos/core#prefLabel> ?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:<http://jena.hpl.hp.com/ARQ/property#> " +
"SELECT DISTINCT ?p ?label1 ?score1 ?label2 ?score2 " +
"PREFIX text:<http://jena.apache.org/text#> " +
"SELECT DISTINCT ?p ?label1 ?label2 " +
"WHERE{" +
"[] a <[[TYPE_URI]]>; " +
"?p ?v. " +
"{" +
"OPTIONAL {?p <http://www.w3.org/2000/01/rdf-schema#label> ?label1. " +
"(?label1 ?score1) pf:textMatch '[[QUERY]]*'. }" +
"OPTIONAL {?p <http://www.w3.org/2004/02/skos/core#prefLabel> ?label2. " +
"(?label2 ?score2) pf:textMatch '[[QUERY]]*'. } " +
"OPTIONAL {?p <http://www.w3.org/2000/01/rdf-schema#label> (?label1 '[[QUERY]]*' [[LIMIT]]). " +
"?p <http://www.w3.org/2000/01/rdf-schema#label> ?label1. }" +
"OPTIONAL {?p <http://www.w3.org/2004/02/skos/core#prefLabel> (?label2 '[[QUERY]]*' [[LIMIT]]). " +
"?p <http://www.w3.org/2004/02/skos/core#prefLabel> ?label2. }" +
"FILTER (bound(?label1) || bound(?label2))" +
"}" +
"} ORDER BY desc(?score1) LIMIT [[LIMIT]]";
"} LIMIT [[LIMIT]]";

private static final String SUGGEST_PROPERTY_QUERY_TEMPLATE =
"PREFIX pf:<http://jena.hpl.hp.com/ARQ/property#> " +
"SELECT DISTINCT ?p ?label1 ?score1 ?label2 ?score2 " +
"PREFIX text:<http://jena.apache.org/text#> " +
"SELECT DISTINCT ?p ?label1 ?label2 " +
"WHERE{" +
"[] ?p ?v. " +
"{" +
"OPTIONAL {?p <http://www.w3.org/2000/01/rdf-schema#label> ?label1. " +
"(?label1 ?score1) pf:textMatch '[[QUERY]]*'. }" +
"OPTIONAL {?p <http://www.w3.org/2004/02/skos/core#prefLabel> ?label2. " +
"(?label2 ?score2) pf:textMatch '[[QUERY]]*'. } " +
"OPTIONAL {?p <http://www.w3.org/2000/01/rdf-schema#label> (?label1 '[[QUERY]]*' [[LIMIT]]). " +
"?p <http://www.w3.org/2000/01/rdf-schema#label> ?label1. }" +
"OPTIONAL {?p <http://www.w3.org/2004/02/skos/core#prefLabel> (?label2 '[[QUERY]]*' [[LIMIT]]). " +
"?p <http://www.w3.org/2004/02/skos/core#prefLabel> ?label2. }" +
"FILTER (bound(?label1) || bound(?label2))" +
"}" +
"} ORDER BY desc(?score1) LIMIT [[LIMIT]]";
"} LIMIT [[LIMIT]]";

private static final String RECONCILE_QUERY_TEMPLATE =
"PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> " +
"PREFIX pf:<http://jena.hpl.hp.com/ARQ/property#> " +
"PREFIX text:<http://jena.apache.org/text#> " +
"PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+
"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:<http://www.w3.org/2000/01/rdf-schema#> " +
"PREFIX text:<http://jena.apache.org/text#> " +
Expand All @@ -255,11 +257,11 @@ public double getScore() {
"}GROUP BY ?entity LIMIT [[LIMIT]]";

private static final String SEARCH_ENTITY_QUERY_TEMPLATE =
"PREFIX pf:<http://jena.hpl.hp.com/ARQ/property#> " +
"PREFIX text:<http://jena.apache.org/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]]";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/org/deri/grefine/reconcile/sindice/SindiceBroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> guessDomain(String query, int limit, GRefineJsonUtilities jsonUtilities) {
Model model;
Expand Down

0 comments on commit 9a8e494

Please sign in to comment.