Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url Management Refactor #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions conf/backendURLs.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[
[
"http://yodaqa.felk.cvut.cz/fuseki-dbp/dbpedia/query",
"http://yodaqa.felk.cvut.cz/fuseki-fb/freebase/query",
"http://yodaqa.felk.cvut.cz/dbp-labels1",
"http://yodaqa.felk.cvut.cz/dbp-labels2",
"http://yodaqa.felk.cvut.cz/apache/solr/"
]
]
{
"cz.brmlab.yodaqa.dbpediaurl": "http://yodaqa.felk.cvut.cz/fuseki-dbp/dbpedia/query",
"cz.brmlab.yodaqa.freebaseurl": "http://yodaqa.felk.cvut.cz/fuseki-fb/freebase/query",
"cz.brmlab.yodaqa.dbpedialabelurl": "http://yodaqa.felk.cvut.cz/dbp-labels1",
"cz.brmlab.yodaqa.dictionarylabelurl": "http://yodaqa.felk.cvut.cz/dbp-labels2",
"cz.brmlab.yodaqa.solrurl": "http://yodaqa.felk.cvut.cz/apache/solr/"
}
]
6 changes: 2 additions & 4 deletions src/main/java/cz/brmlab/yodaqa/io/web/WebInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import cz.brmlab.yodaqa.provider.UrlManager;
import cz.brmlab.yodaqa.provider.url.UrlManager;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spark.QueryParamsMap;
import spark.Request;
import spark.Response;
import spark.Route;
Expand Down Expand Up @@ -142,7 +140,7 @@ public Object handle(Request request, Response response) {
public Object handle(Request request, Response response) {
response.type("application/json");
response.header("Access-Control-Allow-Origin", "*");
return UrlManager.printState();
return UrlManager.getInstance().printState();

}
});
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cz/brmlab/yodaqa/pipeline/YodaQA.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.brmlab.yodaqa.pipeline;

import cz.brmlab.yodaqa.provider.UrlManager;
import cz.brmlab.yodaqa.provider.url.UrlConstants;
import cz.brmlab.yodaqa.provider.url.UrlManager;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.cas.CAS;
import org.apache.uima.fit.factory.AggregateBuilder;
Expand All @@ -20,7 +21,6 @@
import cz.brmlab.yodaqa.pipeline.structured.DBpediaOntologyAnswerProducer;
import cz.brmlab.yodaqa.pipeline.structured.DBpediaPropertyAnswerProducer;
import cz.brmlab.yodaqa.pipeline.structured.FreebaseOntologyAnswerProducer;
import cz.brmlab.yodaqa.pipeline.AnswerHitlistSerialize;
import cz.brmlab.yodaqa.provider.IPv6Check;
import cz.brmlab.yodaqa.provider.solr.SolrNamedSource;

Expand Down Expand Up @@ -56,7 +56,7 @@ public class YodaQA /* XXX: extends AggregateBuilder ? */ {

//SolrNamedSource.register("guten", "data/guten", null);
//SolrNamedSource.register("enwiki", "collection1", "http://127.0.0.1:8983/solr/");
SolrNamedSource.register("enwiki", "collection1", UrlManager.lookUpUrl(UrlManager.DataBackends.SOLR.ordinal()));
SolrNamedSource.register("enwiki", "collection1", UrlManager.getInstance().getUrl(UrlConstants.SOLR));
} catch (Exception e) {
e.printStackTrace();
System.err.println("*** Exception caught during SolrNamedSource initialization. ***");
Expand Down
208 changes: 0 additions & 208 deletions src/main/java/cz/brmlab/yodaqa/provider/UrlManager.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package cz.brmlab.yodaqa.provider.rdf;

import cz.brmlab.yodaqa.provider.UrlManager;
import cz.brmlab.yodaqa.provider.url.UrlConstants;
import cz.brmlab.yodaqa.provider.url.UrlManager;

/** This is an abstract base class for accessing DBpedia. */

public abstract class DBpediaLookup extends CachedJenaLookup {
public DBpediaLookup() {
/* Replace the first URL below with http://dbpedia.org/sparql
* to use the public DBpedia SPARQL endpoint. */
super(UrlManager.lookUpUrl(UrlManager.DataBackends.DBPEDIA.ordinal()),
super(UrlManager.getInstance().getUrl(UrlConstants.DBPEDIA),
"PREFIX : <http://dbpedia.org/resource/>\n" +
"PREFIX dbpedia2: <http://dbpedia.org/property/>\n" +
"PREFIX dbpedia: <http://dbpedia.org/>\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import com.google.gson.Gson;
import com.hp.hpl.jena.rdf.model.Literal;

import cz.brmlab.yodaqa.provider.UrlManager;
import cz.brmlab.yodaqa.provider.url.UrlConstants;
import cz.brmlab.yodaqa.provider.url.UrlManager;
import org.slf4j.Logger;

/** A wrapper around DBpedia "Titles" dataset that maps titles to
Expand All @@ -31,8 +32,8 @@
* and disambiguation pages. */

public class DBpediaTitles extends DBpediaLookup {
protected static final String fuzzyLookupUrl = UrlManager.lookUpUrl(UrlManager.DataBackends.LABEL1.ordinal());
protected static final String crossWikiLookupUrl = UrlManager.lookUpUrl(UrlManager.DataBackends.LABEL2.ordinal());
protected static final String fuzzyLookupUrl = UrlManager.getInstance().getUrl(UrlConstants.DBPEDIA_LABEL);
protected static final String crossWikiLookupUrl = UrlManager.getInstance().getUrl(UrlConstants.DICTIONARY_LABEL);

/** A container of enwiki article metadata.
* This must 1:1 map to label-lookup API. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package cz.brmlab.yodaqa.provider.rdf;

import cz.brmlab.yodaqa.provider.UrlManager;
import cz.brmlab.yodaqa.provider.url.UrlConstants;
import cz.brmlab.yodaqa.provider.url.UrlManager;

/** This is an abstract base class for accessing Freebase. */

public abstract class FreebaseLookup extends CachedJenaLookup {
public FreebaseLookup() {
super(UrlManager.lookUpUrl(UrlManager.DataBackends.FREEBASE.ordinal()),
super(UrlManager.getInstance().getUrl(UrlConstants.FREEBASE),
"PREFIX ns: <http://rdf.freebase.com/ns/>\n" +
"");
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/cz/brmlab/yodaqa/provider/url/BackendUrlGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cz.brmlab.yodaqa.provider.url;

import java.util.HashMap;

/**
* Created by bzhao on 12/21/16.
*/
public class BackendUrlGroup extends HashMap<String,String> {
public String getUrl(String urlkey) {
return this.get(urlkey);
}
}
16 changes: 16 additions & 0 deletions src/main/java/cz/brmlab/yodaqa/provider/url/UrlConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cz.brmlab.yodaqa.provider.url;

/**
* Created by bzhao on 12/23/16.
* URL related constants, these are used as:
* - keys in the json dict map of backendUrls.conf
* - system property overrides from CLI,
* eg: -Dcz.brmlab.yodaqa.dbpediaurl=http://yodaqa.felk.cvut.cz/fuseki-dbp/dbpedia/query
*/
public class UrlConstants {
public final static String DBPEDIA = "cz.brmlab.yodaqa.dbpediaurl";
public final static String FREEBASE = "cz.brmlab.yodaqa.freebaseurl";
public final static String DBPEDIA_LABEL = "cz.brmlab.yodaqa.dbpedialabelurl";
public final static String DICTIONARY_LABEL = "cz.brmlab.yodaqa.dictionarylabelurl";
public final static String SOLR = "cz.brmlab.yodaqa.solrurl";
}
Loading