Search in sources :

Example 1 with TableEntry

use of infoeval.main.mysql.TableEntry in project Info-Evaluation by TechnionYP5777.

the class SqlTablesFiller method getInfo.

public TableEntry getInfo(ResultSetRewindable r) throws ClassNotFoundException, SQLException, IOException, ParseException {
    QuerySolution solution = r.nextSolution();
    RDFNode sName = solution.get("sname");
    String spouseName = sName == null || !sName.isLiteral() ? "No Spouse" : sName.asLiteral().getString() + "";
    RDFNode bPlace = solution.get("birth");
    String birthPlace = "No Birth Place";
    if (bPlace != null)
        if (bPlace.isResource())
            birthPlace = (bPlace.asResource() + "").split("resource/")[1];
        else if (bPlace.isLiteral())
            birthPlace = (bPlace.asLiteral() + "").split("@")[0];
    RDFNode dPlace = solution.get("death");
    String deathPlace = "No Death Place";
    if (dPlace != null)
        if (dPlace.isResource())
            deathPlace = (dPlace.asResource() + "").split("resource/")[1];
        else if (dPlace.isLiteral())
            deathPlace = (dPlace.asLiteral() + "").split("@")[0];
    RDFNode occupation = solution.get("occup");
    String occup = "No Occupation";
    if (occupation != null)
        if (occupation.isResource())
            occup = !(occupation.asResource() + "").contains("resource") ? "No Occupation" : (occupation.asResource() + "").split("resource/")[1];
        else if (occupation.isLiteral())
            occup = (occupation.asLiteral() + "").split("@")[0];
    RDFNode spOcuup = solution.get("spOccu");
    String spouseOccupation = "No Spouse Occupation";
    if (spOcuup != null)
        if (spOcuup.isResource())
            spouseOccupation = !(spOcuup.asResource() + "").contains("resource") ? "No Spouse Occupation" : (spOcuup.asResource() + "").split("resource/")[1];
        else if (dPlace.isLiteral())
            spouseOccupation = (spOcuup.asLiteral() + "").split("@")[0];
    RDFNode bDate = solution.get("bDate");
    String birthDate = bDate == null ? "" : !bDate.isLiteral() ? null : bDate.asLiteral().getValue() + "";
    RDFNode dDate = solution.get("dDate");
    String deathDate = null;
    java.sql.Date sqlDeathDate = null;
    if (dDate == null)
        sqlDeathDate = null;
    else {
        deathDate = !dDate.isLiteral() ? null : dDate.asLiteral().getValue() + "";
        if (deathDate.contains(".") || deathDate.contains("c."))
            sqlDeathDate = null;
        else if (deathDate.split("-").length == 1 && deathDate.matches("[0-9]+") && deathDate.length() <= 4)
            sqlDeathDate = stringToSqlDate(deathDate, new SimpleDateFormat("yyyy"));
        else if (deathDate.matches("[0-9][0-9][0-9][0-9][-][0-9][0-9][-][0-9][0-9]"))
            sqlDeathDate = stringToSqlDate(deathDate, new SimpleDateFormat("yyyy-MM-dd"));
        else if (deathDate.matches("--[0-9][0-9][-][0-9][0-9]"))
            sqlDeathDate = stringToSqlDate(deathDate.substring(2, deathDate.length()), new SimpleDateFormat("MM-dd"));
        int monthNum = 1;
        for (String month : months) {
            if (deathDate.equals(month)) {
                sqlDeathDate = stringToSqlDate(monthNum + "", new SimpleDateFormat("MM"));
                break;
            }
            if (deathDate.startsWith(month)) {
                String parseDeathDate = deathDate.split(" ")[1] + "-" + monthNum;
                sqlDeathDate = stringToSqlDate(parseDeathDate, new SimpleDateFormat("yyyy-MM"));
                break;
            }
            ++monthNum;
        }
    }
    java.sql.Date sqlBirthDate = null;
    if (birthDate.contains(".") || birthDate.contains("c."))
        sqlBirthDate = null;
    else if (birthDate.split("-").length == 1 && birthDate.matches("[0-9]+") && birthDate.length() <= 4)
        sqlBirthDate = stringToSqlDate(birthDate, new SimpleDateFormat("yyyy"));
    else if (birthDate.matches("--[0-9][0-9][-][0-9][0-9]"))
        sqlDeathDate = stringToSqlDate(birthDate.substring(2, birthDate.length()), new SimpleDateFormat("MM-dd"));
    else if (birthDate.matches("[0-9][0-9][0-9][0-9][-][0-9][0-9][-][0-9][0-9]"))
        sqlBirthDate = stringToSqlDate(birthDate, new SimpleDateFormat("yyyy-MM-dd"));
    int monthNum = 1;
    for (String month : months) {
        if (birthDate.equals(month)) {
            sqlBirthDate = stringToSqlDate(monthNum + "", new SimpleDateFormat("MM"));
            break;
        }
        if (birthDate.startsWith(month)) {
            String parseBirthDate = birthDate.split(" ")[1] + "-" + monthNum;
            sqlBirthDate = stringToSqlDate(parseBirthDate, new SimpleDateFormat("yyyy-MM"));
            break;
        }
        ++monthNum;
    }
    return new TableEntry("", "", birthPlace, deathPlace, sqlBirthDate, sqlDeathDate, occup, spouseName, spouseOccupation, (solution.get("photo") == null ? "No Photo" : solution.get("photo") + ""), "");
}
Also used : TableEntry(infoeval.main.mysql.TableEntry) QuerySolution(org.apache.jena.query.QuerySolution) SimpleDateFormat(java.text.SimpleDateFormat) RDFNode(org.apache.jena.rdf.model.RDFNode) Date(java.sql.Date)

Example 2 with TableEntry

use of infoeval.main.mysql.TableEntry in project Info-Evaluation by TechnionYP5777.

the class SqlRunnerTest method getSameBirthPlaceCouplesTest.

@Ignore
@Test
public void getSameBirthPlaceCouplesTest() throws Exception {
    for (TableEntry te : querun.getSameBirthPlaceCouples()) {
        String sName = te.getSpouseName(), checkBirthPlaceQuery = "SELECT birthPlace FROM basic_info WHERE name=? LIMIT 1";
        Object[] inp = new Object[1];
        inp[0] = sName;
        ArrayList<Row> res = querun.runQuery(checkBirthPlaceQuery, inp);
        Row row = res.get(0);
        assertEquals(te.getBirthPlace(), (String) row.row.get(0).getValue().cast(row.row.get(0).getKey()));
    }
}
Also used : TableEntry(infoeval.main.mysql.TableEntry) Row(infoeval.main.mysql.Row) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with TableEntry

use of infoeval.main.mysql.TableEntry in project Info-Evaluation by TechnionYP5777.

the class InfoevalServiceImp method getBornInPlaceYear.

@Override
@RequestMapping(path = "Queries/Query2", method = RequestMethod.GET)
public ArrayList<TableEntry> getBornInPlaceYear(String place, String year) throws Exception {
    SqlRunner runner = new SqlRunner();
    ArrayList<TableEntry> $ = runner.getBornInPlaceBeforeYear(place, year);
    logger.log(Level.INFO, "Born in place before year was called.\n Parameters:" + "Place:" + place + ", Year:" + year);
    logger.log(Level.INFO, "list size:" + $.size());
    return $;
}
Also used : TableEntry(infoeval.main.mysql.TableEntry) SqlRunner(infoeval.main.mysql.SqlRunner) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with TableEntry

use of infoeval.main.mysql.TableEntry in project Info-Evaluation by TechnionYP5777.

the class SqlRunnerTest method getPersonalInfoNotInDBTest.

@Test
public void getPersonalInfoNotInDBTest() throws Exception {
    TableEntry te = querun.getPersonalInfo(Integer.parseInt((Jsoup.connect("https://en.wikipedia.org/w/api.php?action=query&titles=Angela_Merkel" + "&prop=pageimages&format=xml&pithumbsize=350").get() + "").split("pageid=\"")[1].split("\"")[0]));
    assertEquals(te.getUrl(), "https://en.wikipedia.org/?curid=72671");
    assertEquals(te.getName(), "Angela Merkel");
    assertEquals(te.getBirthPlace(), "West Germany");
    assertEquals(te.getDeathPlace(), "No Death Place");
    assertEquals(te.getBirthExpandedPlace(), "West Germany");
    assertEquals(te.getDeathExpandedPlace(), "No Death Place");
    assertEquals((te.getBirthDate() + ""), "1954-07-17");
    assertEquals(te.getDeathDate(), null);
    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/Angela_Merkel_Juli_2010_-_3zu4.jpg");
    assertEquals(te.getOverview().split(" ")[1], "Dorothea");
}
Also used : TableEntry(infoeval.main.mysql.TableEntry) Test(org.junit.Test)

Example 5 with TableEntry

use of infoeval.main.mysql.TableEntry in project Info-Evaluation by TechnionYP5777.

the class SqlRunnerTest method getBornInPlaceBeforeYearTest.

@Test
public void getBornInPlaceBeforeYearTest() throws Exception {
    for (TableEntry te : querun.getBornInPlaceBeforeYear("Japan", "1970")) {
        java.sql.Date birthDate = te.getBirthDate();
        String birthPlace = te.getBirthPlace();
        assert Integer.parseInt(new SimpleDateFormat("yyyy").format(birthDate)) < 1970;
        assert birthPlace.contains("Japan");
    }
}
Also used : TableEntry(infoeval.main.mysql.TableEntry) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

TableEntry (infoeval.main.mysql.TableEntry)17 Test (org.junit.Test)12 SimpleDateFormat (java.text.SimpleDateFormat)6 Date (java.sql.Date)5 SqlRunner (infoeval.main.mysql.SqlRunner)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 QuerySolution (org.apache.jena.query.QuerySolution)2 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 Ignore (org.junit.Ignore)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Extractor (infoeval.main.WikiData.Extractor)1 Row (infoeval.main.mysql.Row)1