Skip to content

Commit

Permalink
Ready for first beta
Browse files Browse the repository at this point in the history
  • Loading branch information
D063520 committed Dec 19, 2015
1 parent b2e3af3 commit 7f5a470
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
31 changes: 14 additions & 17 deletions src/main/java/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public class Index {


String octavePath="/usr/local/bin/octave";
//String labels = "/Users/Dennis/Downloads/labels-en-uris_it.nt";
String dump = "/Users/Dennis/Downloads/dump-it.nt";
String dump = "/Users/Dennis/Downloads/dump/dump.nt";


private HashMap<String,Integer> mapIn = new HashMap<String,Integer>();
Expand All @@ -53,44 +52,35 @@ public OpenMapRealMatrix get(String[] URI) throws IllegalArgumentException{
int k=0;
long startTime = System.currentTimeMillis();
for (String uri : URI){
//System.out.println(uri);
if (mapIn.containsKey(uri)){
tmp[k] = mapIn.get(uri).toString();
} else if (mapInRelation.containsKey(uri)){
//System.out.println("size mapIn: "+ mapIn.size());
tmp[k] = ((Integer)(mapIn.size()+1+mapInRelation.get(uri))).toString();
//System.out.println("mapInRelation index: "+ mapInRelation.get(uri));
} else {
throw new IllegalArgumentException("The URI "+ uri +" is not in the index!");
}
k++;
}
String indeces = String.join(", ", tmp);
//System.out.println(indeces);

//Selects the submatrix containing the rows and columns contained in indeces
//String func="ans=full(B(["+indeces+" ] , [ "+indeces+"]))";
startTime = System.currentTimeMillis();
octave.eval("C = full(B(["+indeces+" ] , [ "+indeces+"]));");
octave.eval("C = full(B(["+indeces+" ] , [ "+indeces+"]))");
long estimatedTime = System.currentTimeMillis() - startTime;
System.out.println("eval: "+estimatedTime);
OctaveDouble ans = octave.get(OctaveDouble.class, "C");
double[] a = ans.getData();
estimatedTime = System.currentTimeMillis() - startTime;
System.out.println("Retrive: "+estimatedTime);
//int[][] A=new int[URI.length][URI.length];
OpenMapRealMatrix B = new OpenMapRealMatrix(URI.length,URI.length);
System.out.println("Length"+URI.length);
for (int i=0; i<URI.length; i++){
for (int j=0; j<URI.length; j++){
//A[i][j]=(int)a[j+URI.length*i];
if (a[i+URI.length*j]!=0){
B.setEntry(i, j, a[i+URI.length*j]);
}
//System.out.println(A[i][j]);
}
}
//System.out.println(A.toString());
return B;
}

Expand All @@ -105,6 +95,7 @@ public String get(Integer i) throws IOException, ClassNotFoundException{
}

public void index() throws IOException, ClassNotFoundException{
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
//create the index folder
File folder = new File("index/");
if (!folder.exists()) folder.mkdir();
Expand All @@ -128,7 +119,7 @@ public void run() {
Integer i=1;
Integer before=0;
int r=1;
System.out.println("Parse the dump and search for all subjects objects...");
System.out.println("Parse the dump and search for all subjects objects and relations ...");
System.out.println("If this slows down, and does not come to an end, you probably need more RAM!");
while (iter.hasNext()) {
Triple next = iter.next();
Expand Down Expand Up @@ -163,7 +154,6 @@ public void run() {
System.out.println("Number resources: "+i);
System.out.println("Number relations: "+r);
executor.shutdownNow();
System.out.println("size mapIn: "+ mapIn.size());

iter = new PipedRDFIterator<Triple>();
final PipedRDFStream<Triple> inputStream2 = new PipedTriplesStream(iter);
Expand Down Expand Up @@ -192,8 +182,6 @@ public void run() {
Object s = mapIn.get(next.getSubject().toString());
Object p = mapInRelation.get(next.getPredicate().toString());
Object o = mapIn.get(next.getObject().toString());
//System.out.println(next.getSubject().toString()+next.getPredicate().toString()+next.getObject().toString());
//System.out.println(s.toString()+p.toString()+o.toString());
if (s!=null){
if (s!=null && o!=null){
printStreamI.print(s + " " + o + " 1\n");
Expand Down Expand Up @@ -223,9 +211,9 @@ public void run() {

System.out.println("Number triples: " + j);
System.out.println("The shortest paths are computed ... ");
//Use the octave instance to compute matrix multiplication


//Use the octave instance to compute matrix multiplication

//Compute the shortest path of length maximal 3
octave.eval("load "+System.getProperty("user.dir")+"/index/matrixI1"+"; ");
Expand Down Expand Up @@ -380,5 +368,14 @@ public void run() {
octave.eval("clear D6;");
*/

//To print out the matrix in DOK format uncomment this lines
/*
octave.eval("[i,j,val] = find(B);");
octave.eval("data_dump = [i,j,val];");
octave.eval("C = [i';j';val'];");
octave.eval("fid = fopen(\'"+System.getProperty("user.dir")+"/index/export"+"\',\'w\');");
octave.eval("fprintf( fid,\'%d %d %d\\n', C );");
*/

}
}
2 changes: 1 addition & 1 deletion src/main/java/Server2.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
System.out.println("Indexing starts ...");
Index i = new Index();
i.index();
System.out.println("\n\nIndexing finished!");
System.out.println("\nIndexing finished!");
System.out.println("I'm ready!");

ServerSocket serverSocket = new ServerSocket(1112);
Expand Down

0 comments on commit 7f5a470

Please sign in to comment.