Search in sources :

Example 21 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project jena by apache.

the class ModelHelper method statement.

public static Statement statement(String fact) {
    StringTokenizer st = new StringTokenizer(fact);
    Resource sub = resource(st.nextToken());
    Property pred = property(st.nextToken());
    RDFNode obj = rdfNode(st.nextToken());
    return builderModel.createStatement(sub, pred, obj);
}
Also used : StringTokenizer(java.util.StringTokenizer) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 22 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project Info-Evaluation by TechnionYP5777.

the class SqlRunner method getPersonalInfo.

@SuppressWarnings("unchecked")
public TableEntry getPersonalInfo(String name) throws ClassNotFoundException, SQLException, IOException, ParseException {
    Object[] inp = new Object[] { name };
    ArrayList<Row> res = conn.runQuery("SELECT name FROM basic_info WHERE name = ?", inp);
    String newName = WordUtils.capitalize(name).replaceAll(" ", "_");
    if (res.isEmpty()) {
        return getPersonalInfoFromDBpedia(newName);
    }
    ArrayList<Row> id_result = conn.runQuery("SELECT serialized_id " + "FROM serialized_query_results " + "WHERE query_identifier LIKE CONCAT('getPersonalInfo','(',?,')')", inp);
    int serialized_id = -1;
    ArrayList<Row> rows = new ArrayList<>();
    String overviewStr = "";
    if (id_result.isEmpty()) {
        Extractor ext = new Extractor(newName);
        logger.log(Level.INFO, "abstract extraction query is being executed");
        ext.executeQuery(QueryTypes.ABSTRACT);
        ResultSetRewindable results = ext.getResults();
        results.reset();
        QuerySolution solution = results.nextSolution();
        RDFNode overview = solution.get("abstract");
        overviewStr = "No Abstract";
        if (overview != null)
            if (overview.isResource())
                overviewStr = (overview.asResource() + "").split("resource/")[1];
            else if (overview.isLiteral())
                overviewStr = (overview.asLiteral() + "").split("@")[0];
        final String personalInfoQuery = "SELECT SQL_CACHE filtered_info.*, WikiID.wikiPageId " + "FROM (SELECT * FROM basic_info WHERE name = ?) AS filtered_info " + "LEFT JOIN WikiID " + "ON WikiID.name = filtered_info.name " + "LIMIT 1";
        logger.log(Level.INFO, "personal info query is being executed");
        rows = conn.runQuery(personalInfoQuery, inp);
        Object[] toSerilaize = new Object[2];
        toSerilaize[0] = rows;
        toSerilaize[1] = overviewStr;
        String query_identifier = "getPersonalInfo(" + name + ")";
        serialized_id = resultsSer.serializeQueryResults(conn, query_identifier, toSerilaize);
    } else {
        serialized_id = (int) id_result.get(0).row.get(0).getKey();
        Object[] output = (Object[]) resultsSer.deSerializeQueryResults(conn, serialized_id);
        rows = (ArrayList<Row>) output[0];
        overviewStr = (String) output[1];
    }
    Row res_row = rows.get(0);
    String birthPlace = (String) res_row.row.get(1).getValue().cast(res_row.row.get(1).getKey());
    String deathPlace = (String) res_row.row.get(2).getValue().cast(res_row.row.get(2).getKey());
    Date birthDate = null;
    if (!"".equals(res_row.row.get(3).getKey())) {
        birthDate = (java.sql.Date) res_row.row.get(3).getValue().cast(res_row.row.get(3).getKey());
    }
    Date deathDate = null;
    if (!"".equals(res_row.row.get(4).getKey())) {
        deathDate = (java.sql.Date) res_row.row.get(4).getValue().cast(res_row.row.get(4).getKey());
    }
    String occupation = (String) res_row.row.get(5).getValue().cast(res_row.row.get(5).getKey());
    String spouseName = (String) res_row.row.get(6).getValue().cast(res_row.row.get(6).getKey());
    String spouseOccupation = (String) res_row.row.get(7).getValue().cast(res_row.row.get(7).getKey());
    String photoLink = (String) res_row.row.get(8).getValue().cast(res_row.row.get(8).getKey());
    photoLink.replaceAll("'", "\'");
    String wikiPageID = (String) res_row.row.get(9).getValue().cast(res_row.row.get(9).getKey());
    TableEntry te = new TableEntry(wikiURL + wikiPageID, name, birthPlace, deathPlace, birthDate, deathDate, occupation, spouseName, spouseOccupation, photoLink, overviewStr);
    return te;
}
Also used : ArrayList(java.util.ArrayList) Date(java.sql.Date) 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 23 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project Info-Evaluation by TechnionYP5777.

the class SqlRunner method getPersonalInfoFromDBpedia.

public TableEntry getPersonalInfoFromDBpedia(String name) throws ClassNotFoundException, SQLException, IOException, ParseException {
    // Object[] inp = new Object[] { name };
    // ArrayList<Row> id_result = conn.runQuery("SELECT serialized_id " +
    // "FROM serialized_query_results "
    // + "WHERE query_identifier LIKE CONCAT('getPersonalInfo','(',?,')')",
    // inp);
    // int serialized_id = -1;
    TableEntry result;
    // if (id_result.isEmpty()) {
    Extractor ext = new Extractor(name);
    logger.log(Level.INFO, "abstract extraction query is being executed");
    ext.executeQuery(QueryTypes.ABSTRACT);
    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];
    logger.log(Level.INFO, "basic Info By Name extraction query is being executed");
    ext.executeQuery(QueryTypes.BASIC_INFO_BY_NAME);
    ResultSetRewindable basicInfoByNameResults = ext.getResults();
    basicInfoByNameResults.reset();
    SqlTablesFiller filler = new SqlTablesFiller();
    TableEntry te = filler.getInfo(basicInfoByNameResults);
    filler.close();
    result = new TableEntry(te);
    String newName = name.replaceAll("_", " ");
    result.setName(newName);
    result.setUrl("");
    result.setOverview(overviewStr);
    String photoLink = result.getPhotoLink();
    photoLink.replaceAll("'", "\'");
    result.setPhotoLink(photoLink);
    Object[] toSerilaize = new Object[1];
    toSerilaize[0] = result;
    /*
		 * String query_identifier = "getPersonalInfo(" + name + ")";
		 * resultsSer.serializeQueryResults(conn, query_identifier,
		 * toSerilaize); } else { serialized_id = (int)
		 * id_result.get(0).row.get(0).getKey(); Object[] output = (Object[])
		 * resultsSer.deSerializeQueryResults(conn, serialized_id); result =
		 * (TableEntry) output[0]; }
		 */
    return result;
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Extractor(infoeval.main.WikiData.Extractor) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) SqlTablesFiller(infoeval.main.WikiData.SqlTablesFiller) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 24 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project jena by apache.

the class QuerySolutionMap method toString.

@Override
public String toString() {
    String tmp = "";
    String sep = "";
    for (Iterator<String> iter = varNames(); iter.hasNext(); ) {
        String varName = iter.next();
        RDFNode n = _get(varName);
        String nStr = FmtUtils.stringForRDFNode(n);
        tmp = tmp + sep + "( ?" + varName + ", " + nStr + " )";
    }
    return tmp;
}
Also used : RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 25 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project jena by apache.

the class ResultSetFormatter method materialize.

/** Touch every var/value */
private static void materialize(QuerySolution qs) {
    for (Iterator<String> iter = qs.varNames(); iter.hasNext(); ) {
        String vn = iter.next();
        RDFNode n = qs.get(vn);
    }
}
Also used : RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

RDFNode (org.apache.jena.rdf.model.RDFNode)48 Resource (org.apache.jena.rdf.model.Resource)20 QuerySolution (org.apache.jena.query.QuerySolution)9 Model (org.apache.jena.rdf.model.Model)9 Node (org.apache.jena.graph.Node)8 Literal (org.apache.jena.rdf.model.Literal)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Dataset (org.apache.jena.query.Dataset)5 Property (org.apache.jena.rdf.model.Property)5 Date (java.sql.Date)4 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)4 TextIndexException (org.apache.jena.query.text.TextIndexException)4 Extractor (infoeval.main.WikiData.Extractor)3 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)3 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)3 Statement (org.apache.jena.rdf.model.Statement)3 ARQException (org.apache.jena.sparql.ARQException)3 UpdateRequest (org.apache.jena.update.UpdateRequest)3 File (java.io.File)2