Skip to content

Commit

Permalink
add limit to wikidata consumer, change query to consider subclass, ad…
Browse files Browse the repository at this point in the history
…d test for all classes
  • Loading branch information
Aleyasen committed Aug 24, 2016
1 parent 439245e commit 91e6092
Show file tree
Hide file tree
Showing 40 changed files with 810 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/dist/
/build/
/store/
build


15 changes: 13 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,22 @@

<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>


<delete dir="dist/resources"/>

<copy todir="dist">
<fileset dir="${basedir}">
<include name="resources/**"/>
</fileset>
</copy>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>

<!--<zipgroupfileset dir="dist" includes="**/*.jar, **/*sparql"/>-->
<!--<zipgroupfileset dir="dist" includes="**/*.*"/>-->
<!--<zipgroupfileset dir="dist" includes="*.jar, *.properties, *.json, *.sparql"/>-->
<!--<zipgroupfileset dir="dist/lib" includes="*.jar"/>-->

<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
Expand Down
Binary file removed build/classes/type/detect/TypeDetect.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/BooleanConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/ByteConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/Converter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/DateConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/Discovery$1.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/Discovery.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/DoubleConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/FloatConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/Garbage.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/Grok.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/GrokUtils.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/IConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/IntegerConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/KeyValue.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/LongConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/Match$1.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/Match.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/Pile.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/ShortConverter.class
Binary file not shown.
Binary file removed build/classes/type/detect/grok/StringConverter.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 4 additions & 3 deletions resources/wikidata/search_by_id.sparql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
PREFIX entity: <http://www.wikidata.org/entity/>
SELECT ?typelabel
SELECT distinct ?typelabel
WHERE
{
entity:{{id}} wdt:P31 ?type .
entity:{{id}} wdt:P31|wdt:P279 ?type .
?type rdfs:label ?typelabel FILTER (LANG(?typelabel)="en") .
}
}

12 changes: 11 additions & 1 deletion src/type/detect/kb/wikidata/WikiDataConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class WikiDataConsumer {
private static final String SEARCH_URL_TEMPLATE = "https://www.wikidata.org/w/api.php?action=wbsearchentities&search={{query}}&language=en&type=item&format=json";
private static final String SPAPRQL_TYPE_QUERY = IOUtils.readFileToString("resources/wikidata/search_by_id.sparql");
private static final String SPARQL_URL_TEMPLATE = "https://query.wikidata.org/sparql?format=json&query={{sparql}}";
private static final Integer DEFUALT_SEARCH_LIMIT = 3;

public static void main(String[] args) {
// final Map<String, Integer> types = getTypes("barack obama");
Expand All @@ -52,7 +53,7 @@ public static Map<String, Integer> getTypes(List<String> terms) {
public static Map<String, Integer> getTypes(String term) {

Map<String, Integer> freq = new HashMap<>();
List<WikiDataSearchEntity> results = search(term);
List<WikiDataSearchEntity> results = search(term, DEFUALT_SEARCH_LIMIT);
System.out.println(results);
for (WikiDataSearchEntity ent : results) {
final List<String> types = recognizeTypesForID(ent.getId());
Expand Down Expand Up @@ -99,6 +100,15 @@ public static List<String> recognizeTypesForID(String id) {
return null;
}

public static List<WikiDataSearchEntity> search(String query, int limit) {
final List<WikiDataSearchEntity> results = search(query);
if (results.size() <= limit) {
return results;
} else {
return results.subList(0, limit);
}
}

public static List<WikiDataSearchEntity> search(String query) {
List<WikiDataSearchEntity> results = new ArrayList<>();
try {
Expand Down
92 changes: 92 additions & 0 deletions test/type/detect/TypeDetectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package type.detect;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import junit.framework.TestCase;

/**
*
* @author Amir
*/
public class TypeDetectTest extends TestCase {

public TypeDetectTest(String testName) {
super(testName);
}

@Override
protected void setUp() throws Exception {
super.setUp();
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
}

/**
* Test of main method, of class TypeDetect.
*/
public void testMain() {
System.out.println("main");
String[] args = null;
TypeDetect.main(args);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of besttype method, of class TypeDetect.
*/
public void testBesttype_String() {
System.out.println("besttype");
String text = "";
TypeDetect instance = new TypeDetect();
String expResult = "";
String result = instance.besttype(text);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of besttype method, of class TypeDetect.
*/
public void testBesttype_List() {
System.out.println("besttype");
List<String> list = Arrays.asList("ITGB3", "ERBB2", "CTLA4");
TypeDetect instance = new TypeDetect();
String result = instance.besttype(list);
assertEquals("protein-coding gene", result);
}

public void testBesttype_List2() {
System.out.println("besttype");
List<String> list = Arrays.asList("Klebsiella", "Escherichia coli", "Bacteria and protozoa", "Neisseria meningitidis");
TypeDetect instance = new TypeDetect();
String result = instance.besttype(list);
assertEquals("taxon", result);
// System.out.println(result);
}

/**
* Test of besttype method, of class TypeDetect.
*/
public void testBesttype_Set() {
System.out.println("besttype");
Set<String> set = null;
TypeDetect instance = new TypeDetect();
String expResult = "";
String result = instance.besttype(set);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

}
45 changes: 45 additions & 0 deletions test/type/detect/kb/KbSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package type.detect.kb;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import type.detect.kb.freebase.FreebaseSuite;
import type.detect.kb.knowledgegraph.KnowledgegraphSuite;
import type.detect.kb.sparql.SparqlSuite;
import type.detect.kb.wikidata.WikidataSuite;

/**
*
* @author Amir
*/
public class KbSuite extends TestCase {

public KbSuite(String testName) {
super(testName);
}

public static Test suite() {
TestSuite suite = new TestSuite("KbSuite");
suite.addTest(WikidataSuite.suite());
suite.addTest(KnowledgegraphSuite.suite());
suite.addTest(SparqlSuite.suite());
suite.addTest(FreebaseSuite.suite());
return suite;
}

@Override
protected void setUp() throws Exception {
super.setUp();
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
}

}
38 changes: 38 additions & 0 deletions test/type/detect/kb/freebase/FreebaseSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package type.detect.kb.freebase;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
*
* @author Amir
*/
public class FreebaseSuite extends TestCase {

public FreebaseSuite(String testName) {
super(testName);
}

public static Test suite() {
TestSuite suite = new TestSuite("FreebaseSuite");
suite.addTest(FreebaseUtilTest.suite());
return suite;
}

@Override
protected void setUp() throws Exception {
super.setUp();
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
}

}
79 changes: 79 additions & 0 deletions test/type/detect/kb/freebase/FreebaseUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package type.detect.kb.freebase;

import java.util.Map;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import net.sf.json.JSONArray;

/**
*
* @author Amir
*/
public class FreebaseUtilTest extends TestCase {

public FreebaseUtilTest(String testName) {
super(testName);
}

public static Test suite() {
TestSuite suite = new TestSuite(FreebaseUtilTest.class);
return suite;
}

@Override
protected void setUp() throws Exception {
super.setUp();
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
}

/**
* Test of main method, of class FreebaseUtil.
*/
public void testMain() {
System.out.println("main");
String[] args = null;
FreebaseUtil.main(args);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of search method, of class FreebaseUtil.
*/
public void testSearch() {
System.out.println("search");
String query = "";
String mql_query_file = "";
int limit = 0;
JSONArray expResult = null;
JSONArray result = FreebaseUtil.search(query, mql_query_file, limit);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of fetch method, of class FreebaseUtil.
*/
public void testFetch() {
System.out.println("fetch");
String query_template_file = "";
Map<String, String> params = null;
JSONArray expResult = null;
JSONArray result = FreebaseUtil.fetch(query_template_file, params);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

}
Loading

0 comments on commit 91e6092

Please sign in to comment.