use of legato.LEGATO in project legato by DOREMUS-ANR.
the class SILK method link.
public static void link(String dirCluster) throws IOException, InterruptedException {
LEGATO legato = LEGATO.getInstance();
File file = new File(dirCluster + File.separator + "configFile.xml");
try {
Process process = Runtime.getRuntime().exec("java -DconfigFile=" + file + " -jar " + legato.getPath() + File.separator + "silk.jar");
InputStream stderr = process.getErrorStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stderr));
String line = reader.readLine();
while (line != null && !line.trim().equals("--EOF--")) {
line = reader.readLine();
}
} catch (IOException ex) {
ex.printStackTrace();
}
return;
}
use of legato.LEGATO in project legato by DOREMUS-ANR.
the class ModelManager method getObjResources.
/**
********
** Get all resources having the value "object" in their path.
*********
*/
public static List<Resource> getObjResources(Model model, RDFNode object) {
LEGATO legato = LEGATO.getInstance();
List<Resource> resources = new ArrayList<Resource>();
for (String className : legato.getClassResources()) {
String sparqlQueryString = "prefix : <urn:ex:>" + "SELECT DISTINCT ?resource WHERE {" + "{?resource a <" + className + "> ;" + "(:|!:)* \"" + object.toString() + "\"}" + "}";
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet queryResults = qexec.execSelect();
while (queryResults.hasNext()) {
QuerySolution qs = queryResults.nextSolution();
resources.add(qs.getResource("?resource"));
}
qexec.close();
}
return resources;
}
use of legato.LEGATO in project legato by DOREMUS-ANR.
the class Sakey method extractKeys.
public static KeyList extractKeys(File file, KeyList keys) throws IOException {
LEGATO legato = LEGATO.getInstance();
ProcessBuilder pbSource = new ProcessBuilder("java", "-jar", legato.getPath() + File.separator + "sakey.jar", file.toString(), "1");
pbSource.directory(new File(legato.getPath() + File.separator));
Process pSource = pbSource.start();
/**
*****
* Parse the results
******
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(pSource.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
/**
*****
* Parse the generated keys
******
*/
if (!builder.toString().contains("0-almost keys:[]")) {
String[] tab1 = builder.toString().split("0-almost keys:");
for (String k : getKeys(tab1[1].substring(1, tab1[1].length() - 2))) {
Key key = new Key();
String[] tab2 = k.split(", ");
for (String property : tab2) {
// For each property
key.addProperty(property);
}
keys.add(key);
}
}
return keys;
}
use of legato.LEGATO in project legato by DOREMUS-ANR.
the class SupportMergedKeys method rank.
public static HashSet<String> rank(KeyList mKeys, File srcFile, File tgtFile) throws IOException {
LEGATO legato = LEGATO.getInstance();
/**
****
* Get All Merged Keys
*****
*/
// will contain all merged keys
HashSet<HashSet<String>> keys = new HashSet<>();
Iterator iter = mKeys.iterator();
while (// For each merged key
iter.hasNext()) {
HashSet<String> properties = new HashSet<>();
Key key = (Key) iter.next();
Iterator iterProp = key.iterator();
while (// For each property
iterProp.hasNext()) {
String property = (String) iterProp.next();
properties.add(property);
}
keys.add(properties);
}
/**
****
* Support computing
*****
*/
HashMap<String, HashSet<String>> srcResources = fileParsing(srcFile.toString());
computeSupport(keys, srcResources);
NBs = 100;
allInstances.clear();
cib = true;
HashMap<String, HashSet<String>> tgtResources = fileParsing(tgtFile.toString());
computeSupport(keys, tgtResources);
NBt = 100;
ValueComparator<HashSet<String>> compSource = new ValueComparator<HashSet<String>>(keysSource);
TreeMap<HashSet<String>, String> mapTrieeSource = new TreeMap<HashSet<String>, String>(compSource);
mapTrieeSource.putAll(keysSource);
ValueComparator<HashSet<String>> compTarget = new ValueComparator<HashSet<String>>(keysTarget);
TreeMap<HashSet<String>, String> mapTrieeTarget = new TreeMap<HashSet<String>, String>(compTarget);
mapTrieeTarget.putAll(keysTarget);
/**
****
* Keys Ranking
*****
*/
HashMap<HashSet<String>, String> mergedKeys = new HashMap<HashSet<String>, String>();
Iterator iterSource = mapTrieeSource.entrySet().iterator();
while (iterSource.hasNext()) {
Map.Entry keySource = (Map.Entry) iterSource.next();
Iterator iterTarget = mapTrieeTarget.entrySet().iterator();
while (iterTarget.hasNext()) {
Map.Entry keyTarget = (Map.Entry) iterTarget.next();
if (keySource.getKey().equals(keyTarget.getKey())) {
float s = Float.valueOf((String) keySource.getValue());
float t = Float.valueOf((String) keyTarget.getValue());
float rankValue = s * t;
mergedKeys.put((HashSet<String>) keySource.getKey(), String.valueOf(rankValue));
}
}
}
ValueComparator<HashSet<String>> compMerg = new ValueComparator<HashSet<String>>(mergedKeys);
TreeMap<HashSet<String>, String> mapTrieeMerg = new TreeMap<HashSet<String>, String>(compMerg);
mapTrieeMerg.putAll(mergedKeys);
/**
****
* Return the first key (with the highest score)
*****
*/
HashSet<String> res;
if (mapTrieeMerg.isEmpty())
res = null;
else
res = mapTrieeMerg.firstEntry().getKey();
return res;
}
Aggregations