Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link
 public static void get_ND_Matches() throws IOException{
 @SuppressWarnings("rawtypes")
 List<String> DBpediaClassesArray = new ArrayList<String>();
 List<String> YagoClassesArray = new ArrayList<String>();
 DBpediaClassesArray = new ArrayList<String>( ClassesRetrieval.getDBpediaClasses());
 YagoClassesArray = new ArrayList<String>( ClassesRetrieval.fileToArrayListYago());
 String YagoClassWithMaxMatches="";
 HashMap<String,Integer> mappingYagoLabelMaxValue = new HashMap<String,Integer>();
 int NumberOfCommonInstances; 
 HashMap<String,ArrayList<String>> MappingYagoClassWithInstances = new HashMap<>();
 
 for(String yagoClass:YagoClassesArray){
 MappingYagoClassWithInstances.put(yagoClass, GetYagooClassInstances(yagoClass));
 System.out.println("Done for : "+yagoClass );
 } 
 for(String dbClass:DBpediaClassesArray){
 ArrayList<String> DBpediaInstancesArray = GetDBpediaClassInstances(dbClass);
 for(Map.Entry<String, ArrayList<String>> YagoMapEntry : MappingYagoClassWithInstances.entrySet()){
 String yagoClass=YagoMapEntry.getKey();
 Set<String> IntersectionSet =Sets.intersection(Sets.newHashSet(DBpediaInstancesArray), Sets.newHashSet(YagoMapEntry.getValue()));
 //System.out.println(dbClass + " and "+ yagoClass+ " = "+ IntersectionSet.size());
 NumberOfCommonInstances = IntersectionSet.size();
 mappingYagoLabelMaxValue.put(yagoClass, NumberOfCommonInstances);
 } 
 int MaximumValueOfIntersection=(Collections.max(mappingYagoLabelMaxValue.values()));
 for(Entry<String, Integer> YagoLabelToValueEntry:mappingYagoLabelMaxValue.entrySet()){
 if(YagoLabelToValueEntry.getValue()==MaximumValueOfIntersection && MaximumValueOfIntersection != 0){
 YagoClassWithMaxMatches = YagoLabelToValueEntry.getKey();
 }
 if(MaximumValueOfIntersection==0){
 YagoClassWithMaxMatches = "Nothing in yago";
 }
 }
 System.out.println("-------------------------------");
 System.out.println(dbClass+" Corresponds to "+ YagoClassWithMaxMatches+" with : "+MaximumValueOfIntersection);
 System.out.println("-------------------------------");
 
 }
}

Actor from DBPEDIA Corresponds to Yago_Actor

Album from DBPEDIA Corresponds to Yago_Album

SomeClass from DBPEDIA Corresponds to nothing in Yago

 public static void get_ND_Matches() throws IOException{
 @SuppressWarnings("rawtypes")
 List<String> DBpediaClassesArray = new ArrayList<String>();
 List<String> YagoClassesArray = new ArrayList<String>();
 DBpediaClassesArray = new ArrayList<String>( ClassesRetrieval.getDBpediaClasses());
 YagoClassesArray = new ArrayList<String>( ClassesRetrieval.fileToArrayListYago());
 String YagoClassWithMaxMatches="";
 HashMap<String,Integer> mappingYagoLabelMaxValue = new HashMap<String,Integer>();
 int NumberOfCommonInstances; 
 HashMap<String,ArrayList<String>> MappingYagoClassWithInstances = new HashMap<>();
 
 for(String yagoClass:YagoClassesArray){
 MappingYagoClassWithInstances.put(yagoClass, GetYagooClassInstances(yagoClass));
 System.out.println("Done for : "+yagoClass );
 } 
 for(String dbClass:DBpediaClassesArray){
 ArrayList<String> DBpediaInstancesArray = GetDBpediaClassInstances(dbClass);
 for(Map.Entry<String, ArrayList<String>> YagoMapEntry : MappingYagoClassWithInstances.entrySet()){
 String yagoClass=YagoMapEntry.getKey();
 Set<String> IntersectionSet =Sets.intersection(Sets.newHashSet(DBpediaInstancesArray), Sets.newHashSet(YagoMapEntry.getValue()));
 //System.out.println(dbClass + " and "+ yagoClass+ " = "+ IntersectionSet.size());
 NumberOfCommonInstances = IntersectionSet.size();
 mappingYagoLabelMaxValue.put(yagoClass, NumberOfCommonInstances);
 } 
 int MaximumValueOfIntersection=(Collections.max(mappingYagoLabelMaxValue.values()));
 for(Entry<String, Integer> YagoLabelToValueEntry:mappingYagoLabelMaxValue.entrySet()){
 if(YagoLabelToValueEntry.getValue()==MaximumValueOfIntersection && MaximumValueOfIntersection != 0){
 YagoClassWithMaxMatches = YagoLabelToValueEntry.getKey();
 }
 if(MaximumValueOfIntersection==0){
 YagoClassWithMaxMatches = "Nothing in yago";
 }
 }
 System.out.println("-------------------------------");
 System.out.println(dbClass+" Corresponds to "+ YagoClassWithMaxMatches+" with : "+MaximumValueOfIntersection);
 System.out.println("-------------------------------");
 
 }
}

Actor from DBPEDIA Corresponds to Yago_Actor

Album from DBPEDIA Corresponds to Yago_Album

SomeClass from DBPEDIA Corresponds to nothing in Yago

 public static void get_ND_Matches() throws IOException{
 @SuppressWarnings("rawtypes")
 List<String> DBpediaClassesArray = new ArrayList<String>();
 List<String> YagoClassesArray = new ArrayList<String>();
 DBpediaClassesArray = new ArrayList<String>( ClassesRetrieval.getDBpediaClasses());
 YagoClassesArray = new ArrayList<String>( ClassesRetrieval.fileToArrayListYago());
 String YagoClassWithMaxMatches="";
 HashMap<String,Integer> mappingYagoLabelMaxValue = new HashMap<String,Integer>();
 int NumberOfCommonInstances; 
 HashMap<String,ArrayList<String>> MappingYagoClassWithInstances = new HashMap<>();
 
 for(String yagoClass:YagoClassesArray){
 MappingYagoClassWithInstances.put(yagoClass, GetYagooClassInstances(yagoClass));
 System.out.println("Done for : "+yagoClass );
 } 
 for(String dbClass:DBpediaClassesArray){
 ArrayList<String> DBpediaInstancesArray = GetDBpediaClassInstances(dbClass);
 for(Map.Entry<String, ArrayList<String>> YagoMapEntry : MappingYagoClassWithInstances.entrySet()){
 String yagoClass=YagoMapEntry.getKey();
 Set<String> IntersectionSet =Sets.intersection(Sets.newHashSet(DBpediaInstancesArray), Sets.newHashSet(YagoMapEntry.getValue()));
 //System.out.println(dbClass + " and "+ yagoClass+ " = "+ IntersectionSet.size());
 NumberOfCommonInstances = IntersectionSet.size();
 mappingYagoLabelMaxValue.put(yagoClass, NumberOfCommonInstances);
 } 
 int MaximumValueOfIntersection=(Collections.max(mappingYagoLabelMaxValue.values()));
 for(Entry<String, Integer> YagoLabelToValueEntry:mappingYagoLabelMaxValue.entrySet()){
 if(YagoLabelToValueEntry.getValue()==MaximumValueOfIntersection && MaximumValueOfIntersection != 0){
 YagoClassWithMaxMatches = YagoLabelToValueEntry.getKey();
 }
 if(MaximumValueOfIntersection==0){
 YagoClassWithMaxMatches = "Nothing in yago";
 }
 }
 System.out.println("-------------------------------");
 System.out.println(dbClass+" Corresponds to "+ YagoClassWithMaxMatches+" with : "+MaximumValueOfIntersection);
 System.out.println("-------------------------------");
 
 }
}

Actor from DBPEDIA Corresponds to Yago_Actor

Album from DBPEDIA Corresponds to Yago_Album

SomeClass from DBPEDIA Corresponds to nothing in Yago

slight edit to make question on topic
Source Link
tim
  • 25.3k
  • 3
  • 31
  • 76

Here is the code I use:

Behind the scenes, this code uses getDBpediaClasses and then applies GetDBpediaClassInstances method to get an arrayListArrayList of results for each class. Each ArrayList resulted is then compared to another ArrayListArrayList generated by GetYagooClassInstances for each class of fileToArrayListYago().

Now, because of all the calculations made in the background (there are millions of elements in each array), this process takes hours to execute, because it runs each comparison after another, while it would be better to get them all done at once and then just get the YagoClassWithMaxMatches after all of them have been computed. I was thinking of concurrency, but I am not sure how to add thatfirst wanted to my code.see if there is an easier way.

Are there any suggestions please to make the runtimecode run faster?

Here is the code I use:

Behind the scenes, this code uses getDBpediaClasses and then applies GetDBpediaClassInstances method to get an arrayList of results for each class. Each ArrayList resulted is then compared to another ArrayList generated by GetYagooClassInstances for each class of fileToArrayListYago().

Now, because of all the calculations made in the background (there are millions of elements in each array), this process takes hours to execute, because it runs each comparison after another, while it would be better to get them all done at once and then just get the YagoClassWithMaxMatches after all of them have been computed. I was thinking of concurrency, but I am not sure how to add that to my code..

Are there any suggestions please to make the runtime faster?

Behind the scenes, this code uses getDBpediaClasses and then applies GetDBpediaClassInstances method to get an ArrayList of results for each class. Each ArrayList resulted is then compared to another ArrayList generated by GetYagooClassInstances for each class of fileToArrayListYago().

Now, because of all the calculations made in the background (there are millions of elements in each array), this process takes hours to execute, because it runs each comparison after another, while it would be better to get them all done at once and then just get the YagoClassWithMaxMatches after all of them have been computed. I was thinking of concurrency, but I first wanted to see if there is an easier way.

Are there any suggestions to make the code run faster?

Source Link
callback
  • 199
  • 2
  • 11

Large arrays make runtime very slow

So I have the following code that takes the input of two arrays, and apply some queries to match elements from DBpediaClassesArray with elements from YagoClassesArray, then it returns the number of elements that are similar in the two ArrayLists.

Here is the code I use:

 public static void get_ND_Matches() throws IOException{
 @SuppressWarnings("rawtypes")
 List<String> DBpediaClassesArray = new ArrayList<String>();
 List<String> YagoClassesArray = new ArrayList<String>();
 DBpediaClassesArray = new ArrayList<String>( ClassesRetrieval.getDBpediaClasses());
 YagoClassesArray = new ArrayList<String>( ClassesRetrieval.fileToArrayListYago());
 String YagoClassWithMaxMatches="";
 HashMap<String,Integer> mappingYagoLabelMaxValue = new HashMap<String,Integer>();
 int NumberOfCommonInstances; 
 HashMap<String,ArrayList<String>> MappingYagoClassWithInstances = new HashMap<>();
 
 for(String yagoClass:YagoClassesArray){
 MappingYagoClassWithInstances.put(yagoClass, GetYagooClassInstances(yagoClass));
 System.out.println("Done for : "+yagoClass );
 } 
 for(String dbClass:DBpediaClassesArray){
 ArrayList<String> DBpediaInstancesArray = GetDBpediaClassInstances(dbClass);
 for(Map.Entry<String, ArrayList<String>> YagoMapEntry : MappingYagoClassWithInstances.entrySet()){
 String yagoClass=YagoMapEntry.getKey();
 Set<String> IntersectionSet =Sets.intersection(Sets.newHashSet(DBpediaInstancesArray), Sets.newHashSet(YagoMapEntry.getValue()));
 //System.out.println(dbClass + " and "+ yagoClass+ " = "+ IntersectionSet.size());
 NumberOfCommonInstances = IntersectionSet.size();
 mappingYagoLabelMaxValue.put(yagoClass, NumberOfCommonInstances);
 } 
 int MaximumValueOfIntersection=(Collections.max(mappingYagoLabelMaxValue.values()));
 for(Entry<String, Integer> YagoLabelToValueEntry:mappingYagoLabelMaxValue.entrySet()){
 if(YagoLabelToValueEntry.getValue()==MaximumValueOfIntersection && MaximumValueOfIntersection != 0){
 YagoClassWithMaxMatches = YagoLabelToValueEntry.getKey();
 }
 if(MaximumValueOfIntersection==0){
 YagoClassWithMaxMatches = "Nothing in yago";
 }
 }
 System.out.println("-------------------------------");
 System.out.println(dbClass+" Corresponds to "+ YagoClassWithMaxMatches+" with : "+MaximumValueOfIntersection);
 System.out.println("-------------------------------");
 
 }
}

This code returns for example:

Actor from DBPEDIA Corresponds to Yago_Actor

Album from DBPEDIA Corresponds to Yago_Album

SomeClass from DBPEDIA Corresponds to nothing in Yago

Etc..

Behind the scenes, this code uses getDBpediaClasses and then applies GetDBpediaClassInstances method to get an arrayList of results for each class. Each ArrayList resulted is then compared to another ArrayList generated by GetYagooClassInstances for each class of fileToArrayListYago().

Now, because of all the calculations made in the background (there are millions of elements in each array), this process takes hours to execute, because it runs each comparison after another, while it would be better to get them all done at once and then just get the YagoClassWithMaxMatches after all of them have been computed. I was thinking of concurrency, but I am not sure how to add that to my code..

Are there any suggestions please to make the runtime faster?

lang-java

AltStyle によって変換されたページ (->オリジナル) /