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);
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations