@Override public NodeParameters clone() { NodeParameters duplicate = new NodeParameters(); if (keyMapping != null) { duplicate.keyMapping = new HashMap<>(this.keyMapping); } if (boolMap != null) { duplicate.boolMap = new TObjectByteHashMap<>(boolMap); } if (longMap != null) { duplicate.longMap = new TObjectLongHashMap<>(longMap); } if (doubleMap != null) { duplicate.doubleMap = new TObjectDoubleHashMap<>(doubleMap); } if (stringMap != null) { duplicate.stringMap = new HashMap<>(this.stringMap); } return duplicate; }
/** * Run SPARQL query * @param uri resource uri * @param p property * @return results map: uri-s (if uri is a subject), uri-o (if uri is an object) */ private TObjectByteHashMap<String> runQuery(String uri, String p){ TObjectByteHashMap<String> results = new TObjectByteHashMap<String>(); Query query; String q; q = "SELECT * WHERE {{?s " + p + " <" + uri + ">. FILTER isIRI(?s). } UNION " + "{<" + uri + "> " + p + " ?o ." + " FILTER isIRI(?o). }} "; logger.debug(q); try { query = QueryFactory.create(q); results = executeQuery(query, p); } catch (Exception e) { e.printStackTrace(); } return results; }
public NodeParameters set(String key, boolean value) { ensureKeyType(key, Type.BOOLEAN); if (boolMap == null) { boolMap = new TObjectByteHashMap<>(); } boolMap.put(key, (value ? (byte) 1 : (byte) 0)); return this; }
/** * Execute RDF triple extraction */ private void exec(NNode node, String list_props, String uri){ if(node.hasChilds()){ String p; for (NNode children : node.getChilds()) { p = children.getValue(); String p_index; TObjectByteHashMap<String> result = new TObjectByteHashMap<String>(); result.putAll(runQuery(uri, "<" + p + ">")); if(result.size()>0){ for(String uri_res : result.keySet()){ p_index = String.valueOf(props_index.get(p)); if(inverseProps){ if(result.get(uri_res) == (byte) 1) p_index = String.valueOf(props_index.get("inv_" + p)); } if(list_props.length()>0){ itemTree.addBranches(list_props + "-" + p_index, extractKey(uri_res)); exec(children, list_props + "-" + p_index, uri_res); } else{ itemTree.addBranches(p_index, extractKey(uri_res)); exec(children, p_index, uri_res); } } } } } }
/** * Execute SPARQL query * @param query sparql query * @param p property * @return results map: uri-s (if uri is a subject), uri-o (if uri is an object) */ private TObjectByteHashMap<String> executeQuery(Query query, String p) { TObjectByteHashMap<String> results = new TObjectByteHashMap<String>(); QueryExecution qexec = null; if(model==null){ if(graphURI == null) qexec = QueryExecutionFactory.sparqlService(endpoint, query); // remote query else qexec = QueryExecutionFactory.sparqlService(endpoint, query, graphURI); // remote query } else qexec = QueryExecutionFactory.create(query, model); // local query try{ //ResultSet res = qexec.execSelect(); ResultSet res = ResultSetFactory.copyResults(qexec.execSelect()) ; QuerySolution qs; String n; while (res.hasNext()) { qs = res.next(); if (qs.get("o") == null) { // get subject n = qs.get("s").toString(); // consider only the type "yago" if (!p.contains("type")) results.put(n, (byte) 1); // target as subject else { if (n.contains("yago")) results.put(n, (byte) 1); // target as subject } } else { // get object n = qs.get("o").toString(); // consider only the type "yago" if (!p.contains("type")) results.put(n, (byte) 0); // target as object else { if (n.contains("yago")) results.put(n, (byte) 0); // target as object } } } } catch(Exception e){ e.printStackTrace(); } finally{ //qexec.close(); } return results; }
public AutoDeltaObjectBoolMap(Function<ByteBuffer, K> keyCreator) { this.changes = new ArrayList<>(5); this.container = new TObjectByteHashMap<>(); this.baselineCommandCount = 0; this.keyCreator = keyCreator; }
public AutoDeltaStringBoolMap() { this.changes = new ArrayList<>(5); this.container = new TObjectByteHashMap<>(); this.baselineCommandCount = 0; }
public AutoDeltaStringByteMap() { this.changes = new ArrayList<>(5); this.container = new TObjectByteHashMap<>(); this.baselineCommandCount = 0; }
public AutoDeltaObjectByteMap(Function<ByteBuffer, K> keyCreator) { this.changes = new ArrayList<>(5); this.container = new TObjectByteHashMap<>(); this.baselineCommandCount = 0; this.keyCreator = keyCreator; }