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

Added type restriction support for DBpedia Spotlight #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
package eu.fbk.dkm.pikes.twm;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.codehaus.jackson.map.ObjectMapper;

import java.io.File;
import java.util.*;

/**
* Created with IntelliJ IDEA.
* User: alessio
* Date: 21/07/14
* Time: 17:15
* To change this template use File | Settings | File Templates.
*/

public class DBpediaSpotlightAnnotate extends Linking {

private static String LABEL = "dbpedia-annotate";
private String confidence;
public static final String DBPS_ADDRESS = "http://spotlight.sztaki.hu:2222/rest";
public static final double DBPS_MIN_CONFIDENCE = 0.33;
private String allowedTypes;
public static final String DBPS_ADDRESS = "http://model.dbpedia-spotlight.org/en";
private static final double DBPS_MIN_CONFIDENCE = 0.33;

public DBpediaSpotlightAnnotate(Properties properties) {
super(properties, properties.getProperty("address", DBPS_ADDRESS) + "/annotate");
confidence = properties.getProperty("min_confidence", Double.toString(DBPS_MIN_CONFIDENCE));
allowedTypes = properties.getProperty("types", null);
}

public List<LinkingTag> tag(String text) throws Exception {

ArrayList<LinkingTag> ret = new ArrayList<>();

Map<String, String> pars = new HashMap<>();
pars.put("confidence", confidence);
if (allowedTypes != null) {
pars.put("types", allowedTypes);
}
pars.put("text", text);

Map<String, Object> userData;
Expand Down Expand Up @@ -67,16 +60,14 @@ public List<LinkingTag> tag(String text) throws Exception {

public static void main(String[] args) {
Properties properties = new Properties();
properties.setProperty("address", "https://knowledgestore2.fbk.eu/dbps/rest/annotate");
properties.setProperty("use_proxy", "0");
properties.setProperty("proxy_url", "proxy.fbk.eu");
properties.setProperty("proxy_port", "3128");
properties.setProperty("address", "http://model.dbpedia-spotlight.org/en");
properties.setProperty("min_confidence", "0.05");
properties.setProperty("types", "Drug,Disease,Chemical_compound");
properties.setProperty("timeout", "2000");

DBpediaSpotlightAnnotate s = new DBpediaSpotlightAnnotate(properties);
try {
String text = Files.toString(new File("/Users/alessio/Desktop/elastic/test-dbps.txt"), Charsets.UTF_8);
String text = "My doctor has suggested to take a pill of Aspirin.";
List<LinkingTag> tags = s.tag(text);
for (LinkingTag tag : tags) {
System.out.println(tag);
Expand Down