Search in sources :

Example 11 with LEGATO

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;
}
Also used : LEGATO(legato.LEGATO) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File)

Example 12 with LEGATO

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;
}
Also used : LEGATO(legato.LEGATO) Query(org.apache.jena.query.Query) QuerySolution(org.apache.jena.query.QuerySolution) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Example 13 with LEGATO

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;
}
Also used : LEGATO(legato.LEGATO) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) Key(legato.keys.def.Key)

Example 14 with LEGATO

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;
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ValueComparator(legato.utils.ValueComparator) LEGATO(legato.LEGATO) StmtIterator(org.apache.jena.rdf.model.StmtIterator) Iterator(java.util.Iterator) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Key(legato.keys.def.Key) HashSet(java.util.HashSet)

Aggregations

LEGATO (legato.LEGATO)14 File (java.io.File)7 Resource (org.apache.jena.rdf.model.Resource)7 Model (org.apache.jena.rdf.model.Model)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 QueryExecution (org.apache.jena.query.QueryExecution)4 FileWriter (java.io.FileWriter)3 Iterator (java.util.Iterator)3 Query (org.apache.jena.query.Query)3 QuerySolution (org.apache.jena.query.QuerySolution)3 ResultSet (org.apache.jena.query.ResultSet)3 Property (org.apache.jena.rdf.model.Property)3 DoubleArray (ca.pfv.spmf.patterns.cluster.DoubleArray)2 AlignmentParser (fr.inrialpes.exmo.align.parser.AlignmentParser)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 TreeMap (java.util.TreeMap)2 Key (legato.keys.def.Key)2