Search in sources :

Example 1 with Extractor

use of infoeval.main.WikiData.Extractor in project Info-Evaluation by TechnionYP5777.

the class ConnectorTest method basicInfoTableSizeTest.

@Ignore
@Test
public void basicInfoTableSizeTest() throws Exception {
    Connector conn = new Connector();
    assert conn.getConnection() != null;
    ArrayList<Row> rows = conn.runQuery("SELECT COUNT(*) FROM basic_info");
    Row row = rows.get(0);
    Entry<Object, Class> col = row.row.get(0);
    Object size = col.getValue().cast(col.getKey());
    assertEquals(ENTRIES_NUM, size);
    Extractor ext = new Extractor();
    ext.executeQuery(QueryTypes.BASIC_INFO);
    assertEquals(ext.getResults().size(), size);
    conn.close();
}
Also used : Connector(infoeval.main.WikiData.Connector) Row(infoeval.main.mysql.Row) Extractor(infoeval.main.WikiData.Extractor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with Extractor

use of infoeval.main.WikiData.Extractor in project Info-Evaluation by TechnionYP5777.

the class ExtractorTest method abstractTest.

@Ignore
@Test
public void abstractTest() {
    String name = "Jessica Zelinka", newName = WordUtils.capitalize(name).replaceAll(" ", "_");
    Extractor extr = new Extractor(newName);
    extr.executeQuery(QueryTypes.ABSTRACT);
    ResultSetRewindable results = extr.getResults();
    results.reset();
    QuerySolution solution = results.nextSolution();
    RDFNode overview = solution.get("abstract");
    String overviewStr = "No Abstract";
    if (overview != null)
        if (overview.isResource())
            overviewStr = (overview.asResource() + "").split("resource/")[1];
        else if (overview.isLiteral())
            overviewStr = (overview.asLiteral() + "").split("@")[0];
    assertEquals(overviewStr, "Jessica Zelinka (born September 3, 1981 in London, Ontario) is a Canadian pentathlete, heptathlete, and 100 m hurdler. Her personal best score is 6599 points for the heptathlon. She was the gold medalist at the 2007 Pan American Games. Zelinka won silver at the 2010 Commonwealth Games and repeated her silver medal at the 2014 Commonwealth Games. At the 2012 Summer Olympics Zelinka finished in 7th overall in both the heptathlon and 100 m hurdles.");
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Extractor(infoeval.main.WikiData.Extractor) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) RDFNode(org.apache.jena.rdf.model.RDFNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Extractor

use of infoeval.main.WikiData.Extractor in project Info-Evaluation by TechnionYP5777.

the class SqlRunner method getPersonalInfo.

public TableEntry getPersonalInfo(int wikiPageID) throws ClassNotFoundException, SQLException, IOException, ParseException {
    Extractor ext = new Extractor(wikiPageID);
    ext.executeQuery(QueryTypes.ABSTRACT_BY_WIKI_PAGE_ID);
    ResultSetRewindable results = ext.getResults();
    results.reset();
    QuerySolution solution = results.nextSolution();
    RDFNode overview = solution.get("abstract");
    String overviewStr = "No Abstract";
    if (overview != null)
        if (overview.isResource())
            overviewStr = (overview.asResource() + "").split("resource/")[1];
        else if (overview.isLiteral())
            overviewStr = (overview.asLiteral() + "").split("@")[0];
    ext.executeQuery(QueryTypes.BASIC_INFO_BY_WIKI_PAGE_ID);
    ResultSetRewindable basicInfoByIdResults = ext.getResults();
    basicInfoByIdResults.reset();
    TableEntry te = SqlTablesFiller.getBasicInfo(basicInfoByIdResults);
    TableEntry result = new TableEntry(te);
    result.setUrl(wikiURL + wikiPageID);
    result.setOverview(overviewStr);
    String photoLink = result.getPhotoLink();
    photoLink.replaceAll("'", "\'");
    int containsQuesmark = photoLink.indexOf("?");
    if (containsQuesmark != -1) {
        photoLink = photoLink.substring(0, containsQuesmark);
    }
    result.setPhotoLink(photoLink);
    return result;
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Extractor(infoeval.main.WikiData.Extractor) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 4 with Extractor

use of infoeval.main.WikiData.Extractor in project Info-Evaluation by TechnionYP5777.

the class ExtractorTest method basicInfoByIDTest.

@Ignore
@Test
public void basicInfoByIDTest() throws Exception {
    int wikiPageID = Integer.parseInt((Jsoup.connect("https://en.wikipedia.org/w/api.php?action=query&titles=Michael_Jackson&prop=pageimages&format=xml&pithumbsize=350").get() + "").split("pageid=\"")[1].split("\"")[0]);
    Extractor extr = new Extractor(wikiPageID);
    extr.executeQuery(QueryTypes.BASIC_INFO_BY_WIKI_PAGE_ID);
    ResultSetRewindable results = extr.getResults();
    results.reset();
    TableEntry te = SqlTablesFiller.getBasicInfo(results);
    assertEquals(te.getName(), "Michael Jackson");
    assertEquals(te.getBirthPlace(), "No Birth Place");
    assertEquals(te.getDeathPlace(), "No Death Place");
    Date birthDate = te.getBirthDate();
    assertNull(birthDate);
    Date deathDate = te.getDeathDate();
    assertNull(deathDate);
    assertEquals(te.getOccupation(), "No Occupation");
    assertEquals(te.getSpouseName(), "No Spouse");
    assertEquals(te.getSpouseOccupation(), "No Spouse Occupation");
    assertEquals(te.getPhotoLink(), "http://commons.wikimedia.org/wiki/Special:FilePath/Michael_Jackson_in_1988.jpg?width=300");
}
Also used : TableEntry(infoeval.main.mysql.TableEntry) Extractor(infoeval.main.WikiData.Extractor) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) Date(java.sql.Date) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Extractor

use of infoeval.main.WikiData.Extractor in project Info-Evaluation by TechnionYP5777.

the class ExtractorTest method basicInfoTest.

@Ignore
@Test
public void basicInfoTest() {
    Extractor extr = new Extractor();
    extr.executeQuery(QueryTypes.BASIC_INFO);
    assertEquals(extr.getResults().size(), ENTRIES_NUM);
}
Also used : Extractor(infoeval.main.WikiData.Extractor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Extractor (infoeval.main.WikiData.Extractor)10 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)6 RDFNode (org.apache.jena.rdf.model.RDFNode)5 QuerySolution (org.apache.jena.query.QuerySolution)4 Connector (infoeval.main.WikiData.Connector)2 Row (infoeval.main.mysql.Row)2 Date (java.sql.Date)2 SqlTablesFiller (infoeval.main.WikiData.SqlTablesFiller)1 TableEntry (infoeval.main.mysql.TableEntry)1 ArrayList (java.util.ArrayList)1