Retrieving synonyms from an ontology
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
-1
down vote
favorite
My question is about my Ontology which retrieves synonyms
from the ontology by using isSynonymOf object property. (Note that
my Ontology file is 260 kb and expected to become 500kb). I am using
following code to retrieve the synonyms. The performance in terms of
response time is very low. It takes a lot of time(minutes) to
display synonyms. How can i improve it?
Note: The problem looks like in similarity algorithm and iterator.
Here is My full Code
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.ontology.SymmetricProperty;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.NodeIterator;
import org.apache.jena.util.FileManager;
import xyzWordAnalyzer;
import cde.model.SimilarityModel;
public class ontologyConnector
private static ontologyConnector instance;
private static OntModel ontModel;
protected static final Sring SOURCE_FILE = "http://abc.owl";
protected static final String NS = SOURCE_FILE + "abc";
public static synchronized ontologyConnector getInstance()
if (instance == null)
instance = new ontologyConnector();
return instance;
public ontologyConnector()
ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
InputStream in = FileManager.get().open(SOURCE_FILE);
ontModel.read(in, "");
public ArrayList<SimilarityModel> getRelatums(String keyword)
ArrayList<String> list = new ArrayList<String>();
keyword = keyword.replaceAll(" ", "_");
SymmetricProperty isSynonymOf = ontModel.getSymmetricProperty("http://www.semanticweb.org/abc#isSynonymOf");
Iterator<Individual> iterInd = ontModel.listIndividuals();
while (iterInd.hasNext())
Individual ind = iterInd.next();
if (ind.getLocalName().equalsIgnoreCase(keyword))
NodeIterator iterVal = ind.listPropertyValues(isSynonymOf);
while (iterVal.hasNext())
list.add(iterVal.nextNode().asResource().getLocalName().toString().replace("_", " "));
list = removeDuplicationfromList(keyword, list);
// list.remove(keyword);
ArrayList<SimilarityModel> simList = new ArrayList<SimilarityModel>();
Double tot = (double) 0;
WordAnalyzer wa = new WordAnalyzer();
for (int i = 0; i < list.size(); i++)
Double tmpDouble = wa.getSimilarity(keyword.toLowerCase(),
list.get(i));
int tmp = 0;
if (Double.isNaN(tmpDouble))
// tmpDouble = (double) -200;
tmp = -200;
else
tmpDouble *= 100;
tot += tmpDouble;
tmp = tmpDouble.intValue();
SimilarityModel simModel = new SimilarityModel(list.get(i), tmp);
simList.add(simModel);
Double avg = tot / simList.size();
if (!Double.isNaN(avg))
for (int i = 0; i < simList.size(); i++)
if (simList.get(i).getSimilarity() == -200)
simList.get(i).setSimilarity(avg.intValue());
return simList;
private ArrayList<String> removeDuplicationfromList(String str,
ArrayList<String> list)
for (int i = list.size() - 1; i >= 0; i--)
if (list.get(i).toString().equalsIgnoreCase(str))
list.remove(i);
return list;
java performance iterator
 |Â
show 5 more comments
up vote
-1
down vote
favorite
My question is about my Ontology which retrieves synonyms
from the ontology by using isSynonymOf object property. (Note that
my Ontology file is 260 kb and expected to become 500kb). I am using
following code to retrieve the synonyms. The performance in terms of
response time is very low. It takes a lot of time(minutes) to
display synonyms. How can i improve it?
Note: The problem looks like in similarity algorithm and iterator.
Here is My full Code
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.ontology.SymmetricProperty;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.NodeIterator;
import org.apache.jena.util.FileManager;
import xyzWordAnalyzer;
import cde.model.SimilarityModel;
public class ontologyConnector
private static ontologyConnector instance;
private static OntModel ontModel;
protected static final Sring SOURCE_FILE = "http://abc.owl";
protected static final String NS = SOURCE_FILE + "abc";
public static synchronized ontologyConnector getInstance()
if (instance == null)
instance = new ontologyConnector();
return instance;
public ontologyConnector()
ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
InputStream in = FileManager.get().open(SOURCE_FILE);
ontModel.read(in, "");
public ArrayList<SimilarityModel> getRelatums(String keyword)
ArrayList<String> list = new ArrayList<String>();
keyword = keyword.replaceAll(" ", "_");
SymmetricProperty isSynonymOf = ontModel.getSymmetricProperty("http://www.semanticweb.org/abc#isSynonymOf");
Iterator<Individual> iterInd = ontModel.listIndividuals();
while (iterInd.hasNext())
Individual ind = iterInd.next();
if (ind.getLocalName().equalsIgnoreCase(keyword))
NodeIterator iterVal = ind.listPropertyValues(isSynonymOf);
while (iterVal.hasNext())
list.add(iterVal.nextNode().asResource().getLocalName().toString().replace("_", " "));
list = removeDuplicationfromList(keyword, list);
// list.remove(keyword);
ArrayList<SimilarityModel> simList = new ArrayList<SimilarityModel>();
Double tot = (double) 0;
WordAnalyzer wa = new WordAnalyzer();
for (int i = 0; i < list.size(); i++)
Double tmpDouble = wa.getSimilarity(keyword.toLowerCase(),
list.get(i));
int tmp = 0;
if (Double.isNaN(tmpDouble))
// tmpDouble = (double) -200;
tmp = -200;
else
tmpDouble *= 100;
tot += tmpDouble;
tmp = tmpDouble.intValue();
SimilarityModel simModel = new SimilarityModel(list.get(i), tmp);
simList.add(simModel);
Double avg = tot / simList.size();
if (!Double.isNaN(avg))
for (int i = 0; i < simList.size(); i++)
if (simList.get(i).getSimilarity() == -200)
simList.get(i).setSimilarity(avg.intValue());
return simList;
private ArrayList<String> removeDuplicationfromList(String str,
ArrayList<String> list)
for (int i = list.size() - 1; i >= 0; i--)
if (list.get(i).toString().equalsIgnoreCase(str))
list.remove(i);
return list;
java performance iterator
1
Where can I download the executable project? Where does theOntModel
class come from? Why don't you follow the Java naming conventions ? Who is forcing you into the uglyIterator
API instead of the nice and modernfor (obj : iterable)
? You should answer all these questions in your post. Just edit it.
â Roland Illig
Feb 28 at 4:27
I agree that the question needs to be improved, e. g. with an explanation of what it does. But can anyone explain to me how the downvotes are justified? To me, this does not look like a bad question, and neither an off-topic one.
â Raimund Krämer
Feb 28 at 11:24
Also, @RolandIllig, aren't the ugly Iterator API and the bad naming style what the review answers should be about, rather than being answered by the asker?
â Raimund Krämer
Feb 28 at 11:26
@RaimundKrämer my ontology retrieves related terms when i search a keyword. Primarily, my code do well but when my ontology is growing, then retriving process becomes slow. That is the problem what i am facing with above mentioned code.
â Tolga
Feb 28 at 13:19
1
@Tolga Please add the explanation to the question by editing it, rather than in a comment. Also, the explanation should go into more detail, and it would help a lot if you would add more code to your question, for example the classesOntModel
,SymmetricProperty
and others. There is a lot in your code that is worth a review, but the performance problem lies most likely somewhere else in your code, if at all.
â Raimund Krämer
Feb 28 at 14:52
 |Â
show 5 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
My question is about my Ontology which retrieves synonyms
from the ontology by using isSynonymOf object property. (Note that
my Ontology file is 260 kb and expected to become 500kb). I am using
following code to retrieve the synonyms. The performance in terms of
response time is very low. It takes a lot of time(minutes) to
display synonyms. How can i improve it?
Note: The problem looks like in similarity algorithm and iterator.
Here is My full Code
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.ontology.SymmetricProperty;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.NodeIterator;
import org.apache.jena.util.FileManager;
import xyzWordAnalyzer;
import cde.model.SimilarityModel;
public class ontologyConnector
private static ontologyConnector instance;
private static OntModel ontModel;
protected static final Sring SOURCE_FILE = "http://abc.owl";
protected static final String NS = SOURCE_FILE + "abc";
public static synchronized ontologyConnector getInstance()
if (instance == null)
instance = new ontologyConnector();
return instance;
public ontologyConnector()
ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
InputStream in = FileManager.get().open(SOURCE_FILE);
ontModel.read(in, "");
public ArrayList<SimilarityModel> getRelatums(String keyword)
ArrayList<String> list = new ArrayList<String>();
keyword = keyword.replaceAll(" ", "_");
SymmetricProperty isSynonymOf = ontModel.getSymmetricProperty("http://www.semanticweb.org/abc#isSynonymOf");
Iterator<Individual> iterInd = ontModel.listIndividuals();
while (iterInd.hasNext())
Individual ind = iterInd.next();
if (ind.getLocalName().equalsIgnoreCase(keyword))
NodeIterator iterVal = ind.listPropertyValues(isSynonymOf);
while (iterVal.hasNext())
list.add(iterVal.nextNode().asResource().getLocalName().toString().replace("_", " "));
list = removeDuplicationfromList(keyword, list);
// list.remove(keyword);
ArrayList<SimilarityModel> simList = new ArrayList<SimilarityModel>();
Double tot = (double) 0;
WordAnalyzer wa = new WordAnalyzer();
for (int i = 0; i < list.size(); i++)
Double tmpDouble = wa.getSimilarity(keyword.toLowerCase(),
list.get(i));
int tmp = 0;
if (Double.isNaN(tmpDouble))
// tmpDouble = (double) -200;
tmp = -200;
else
tmpDouble *= 100;
tot += tmpDouble;
tmp = tmpDouble.intValue();
SimilarityModel simModel = new SimilarityModel(list.get(i), tmp);
simList.add(simModel);
Double avg = tot / simList.size();
if (!Double.isNaN(avg))
for (int i = 0; i < simList.size(); i++)
if (simList.get(i).getSimilarity() == -200)
simList.get(i).setSimilarity(avg.intValue());
return simList;
private ArrayList<String> removeDuplicationfromList(String str,
ArrayList<String> list)
for (int i = list.size() - 1; i >= 0; i--)
if (list.get(i).toString().equalsIgnoreCase(str))
list.remove(i);
return list;
java performance iterator
My question is about my Ontology which retrieves synonyms
from the ontology by using isSynonymOf object property. (Note that
my Ontology file is 260 kb and expected to become 500kb). I am using
following code to retrieve the synonyms. The performance in terms of
response time is very low. It takes a lot of time(minutes) to
display synonyms. How can i improve it?
Note: The problem looks like in similarity algorithm and iterator.
Here is My full Code
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.ontology.SymmetricProperty;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.NodeIterator;
import org.apache.jena.util.FileManager;
import xyzWordAnalyzer;
import cde.model.SimilarityModel;
public class ontologyConnector
private static ontologyConnector instance;
private static OntModel ontModel;
protected static final Sring SOURCE_FILE = "http://abc.owl";
protected static final String NS = SOURCE_FILE + "abc";
public static synchronized ontologyConnector getInstance()
if (instance == null)
instance = new ontologyConnector();
return instance;
public ontologyConnector()
ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
InputStream in = FileManager.get().open(SOURCE_FILE);
ontModel.read(in, "");
public ArrayList<SimilarityModel> getRelatums(String keyword)
ArrayList<String> list = new ArrayList<String>();
keyword = keyword.replaceAll(" ", "_");
SymmetricProperty isSynonymOf = ontModel.getSymmetricProperty("http://www.semanticweb.org/abc#isSynonymOf");
Iterator<Individual> iterInd = ontModel.listIndividuals();
while (iterInd.hasNext())
Individual ind = iterInd.next();
if (ind.getLocalName().equalsIgnoreCase(keyword))
NodeIterator iterVal = ind.listPropertyValues(isSynonymOf);
while (iterVal.hasNext())
list.add(iterVal.nextNode().asResource().getLocalName().toString().replace("_", " "));
list = removeDuplicationfromList(keyword, list);
// list.remove(keyword);
ArrayList<SimilarityModel> simList = new ArrayList<SimilarityModel>();
Double tot = (double) 0;
WordAnalyzer wa = new WordAnalyzer();
for (int i = 0; i < list.size(); i++)
Double tmpDouble = wa.getSimilarity(keyword.toLowerCase(),
list.get(i));
int tmp = 0;
if (Double.isNaN(tmpDouble))
// tmpDouble = (double) -200;
tmp = -200;
else
tmpDouble *= 100;
tot += tmpDouble;
tmp = tmpDouble.intValue();
SimilarityModel simModel = new SimilarityModel(list.get(i), tmp);
simList.add(simModel);
Double avg = tot / simList.size();
if (!Double.isNaN(avg))
for (int i = 0; i < simList.size(); i++)
if (simList.get(i).getSimilarity() == -200)
simList.get(i).setSimilarity(avg.intValue());
return simList;
private ArrayList<String> removeDuplicationfromList(String str,
ArrayList<String> list)
for (int i = list.size() - 1; i >= 0; i--)
if (list.get(i).toString().equalsIgnoreCase(str))
list.remove(i);
return list;
java performance iterator
edited Mar 7 at 0:56
asked Feb 28 at 3:26
Tolga
112
112
1
Where can I download the executable project? Where does theOntModel
class come from? Why don't you follow the Java naming conventions ? Who is forcing you into the uglyIterator
API instead of the nice and modernfor (obj : iterable)
? You should answer all these questions in your post. Just edit it.
â Roland Illig
Feb 28 at 4:27
I agree that the question needs to be improved, e. g. with an explanation of what it does. But can anyone explain to me how the downvotes are justified? To me, this does not look like a bad question, and neither an off-topic one.
â Raimund Krämer
Feb 28 at 11:24
Also, @RolandIllig, aren't the ugly Iterator API and the bad naming style what the review answers should be about, rather than being answered by the asker?
â Raimund Krämer
Feb 28 at 11:26
@RaimundKrämer my ontology retrieves related terms when i search a keyword. Primarily, my code do well but when my ontology is growing, then retriving process becomes slow. That is the problem what i am facing with above mentioned code.
â Tolga
Feb 28 at 13:19
1
@Tolga Please add the explanation to the question by editing it, rather than in a comment. Also, the explanation should go into more detail, and it would help a lot if you would add more code to your question, for example the classesOntModel
,SymmetricProperty
and others. There is a lot in your code that is worth a review, but the performance problem lies most likely somewhere else in your code, if at all.
â Raimund Krämer
Feb 28 at 14:52
 |Â
show 5 more comments
1
Where can I download the executable project? Where does theOntModel
class come from? Why don't you follow the Java naming conventions ? Who is forcing you into the uglyIterator
API instead of the nice and modernfor (obj : iterable)
? You should answer all these questions in your post. Just edit it.
â Roland Illig
Feb 28 at 4:27
I agree that the question needs to be improved, e. g. with an explanation of what it does. But can anyone explain to me how the downvotes are justified? To me, this does not look like a bad question, and neither an off-topic one.
â Raimund Krämer
Feb 28 at 11:24
Also, @RolandIllig, aren't the ugly Iterator API and the bad naming style what the review answers should be about, rather than being answered by the asker?
â Raimund Krämer
Feb 28 at 11:26
@RaimundKrämer my ontology retrieves related terms when i search a keyword. Primarily, my code do well but when my ontology is growing, then retriving process becomes slow. That is the problem what i am facing with above mentioned code.
â Tolga
Feb 28 at 13:19
1
@Tolga Please add the explanation to the question by editing it, rather than in a comment. Also, the explanation should go into more detail, and it would help a lot if you would add more code to your question, for example the classesOntModel
,SymmetricProperty
and others. There is a lot in your code that is worth a review, but the performance problem lies most likely somewhere else in your code, if at all.
â Raimund Krämer
Feb 28 at 14:52
1
1
Where can I download the executable project? Where does the
OntModel
class come from? Why don't you follow the Java naming conventions ? Who is forcing you into the ugly Iterator
API instead of the nice and modern for (obj : iterable)
? You should answer all these questions in your post. Just edit it.â Roland Illig
Feb 28 at 4:27
Where can I download the executable project? Where does the
OntModel
class come from? Why don't you follow the Java naming conventions ? Who is forcing you into the ugly Iterator
API instead of the nice and modern for (obj : iterable)
? You should answer all these questions in your post. Just edit it.â Roland Illig
Feb 28 at 4:27
I agree that the question needs to be improved, e. g. with an explanation of what it does. But can anyone explain to me how the downvotes are justified? To me, this does not look like a bad question, and neither an off-topic one.
â Raimund Krämer
Feb 28 at 11:24
I agree that the question needs to be improved, e. g. with an explanation of what it does. But can anyone explain to me how the downvotes are justified? To me, this does not look like a bad question, and neither an off-topic one.
â Raimund Krämer
Feb 28 at 11:24
Also, @RolandIllig, aren't the ugly Iterator API and the bad naming style what the review answers should be about, rather than being answered by the asker?
â Raimund Krämer
Feb 28 at 11:26
Also, @RolandIllig, aren't the ugly Iterator API and the bad naming style what the review answers should be about, rather than being answered by the asker?
â Raimund Krämer
Feb 28 at 11:26
@RaimundKrämer my ontology retrieves related terms when i search a keyword. Primarily, my code do well but when my ontology is growing, then retriving process becomes slow. That is the problem what i am facing with above mentioned code.
â Tolga
Feb 28 at 13:19
@RaimundKrämer my ontology retrieves related terms when i search a keyword. Primarily, my code do well but when my ontology is growing, then retriving process becomes slow. That is the problem what i am facing with above mentioned code.
â Tolga
Feb 28 at 13:19
1
1
@Tolga Please add the explanation to the question by editing it, rather than in a comment. Also, the explanation should go into more detail, and it would help a lot if you would add more code to your question, for example the classes
OntModel
, SymmetricProperty
and others. There is a lot in your code that is worth a review, but the performance problem lies most likely somewhere else in your code, if at all.â Raimund Krämer
Feb 28 at 14:52
@Tolga Please add the explanation to the question by editing it, rather than in a comment. Also, the explanation should go into more detail, and it would help a lot if you would add more code to your question, for example the classes
OntModel
, SymmetricProperty
and others. There is a lot in your code that is worth a review, but the performance problem lies most likely somewhere else in your code, if at all.â Raimund Krämer
Feb 28 at 14:52
 |Â
show 5 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
Design
You have implemented the class as a singleton, but made the constructor public. That makes the use of the singleton pattern kind of useless. Since you want the class to only be instantiated once, which is inside the class itself, you should make it private
.
public ArrayList<SimilarityModel> getRelatums(String keyword)
Especially in the API of a class, i. e. its public members like this method, you should use interfaces or abstract types, rather than specific implementations. If you replace ArrayList<SimilarityModel>
with List<SimilarityModel>
, you can use any implementation of List
that you like, without having to change many parts of your code.
Style
The Java convention for class names is UpperCamelCase
. ontologyConnector
should be OntologyConnector
.
Your names are not only inconsistent in capitalization, but also abbreviation. OntModel
should be written out as OntologyModel
, to fit with OntologyConnector
but also because abbreviations sometimes force the reader to guess what it means and thus destroy the code's readability.
public ArrayList<SimilarityModel> getRelatums(String keyword)
The return type suggests that the method returns a collection of SimilarityModel
s, but is named getRelatums
. It should be called getSimilarityModels
, if that's what it is actually doing. If not, then the name of the type SimilarityModel
might be chosen badly.
As others have already pointed out in the comments, in order to get help with the performance problem you need to add more information and code (e. g. the classes OntModel
and SymmetricProperty
). However in my opinion there is still a lot you can improve in the already available code to make it worth a review. Please add more code to get further suggestions as performance improvements.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Design
You have implemented the class as a singleton, but made the constructor public. That makes the use of the singleton pattern kind of useless. Since you want the class to only be instantiated once, which is inside the class itself, you should make it private
.
public ArrayList<SimilarityModel> getRelatums(String keyword)
Especially in the API of a class, i. e. its public members like this method, you should use interfaces or abstract types, rather than specific implementations. If you replace ArrayList<SimilarityModel>
with List<SimilarityModel>
, you can use any implementation of List
that you like, without having to change many parts of your code.
Style
The Java convention for class names is UpperCamelCase
. ontologyConnector
should be OntologyConnector
.
Your names are not only inconsistent in capitalization, but also abbreviation. OntModel
should be written out as OntologyModel
, to fit with OntologyConnector
but also because abbreviations sometimes force the reader to guess what it means and thus destroy the code's readability.
public ArrayList<SimilarityModel> getRelatums(String keyword)
The return type suggests that the method returns a collection of SimilarityModel
s, but is named getRelatums
. It should be called getSimilarityModels
, if that's what it is actually doing. If not, then the name of the type SimilarityModel
might be chosen badly.
As others have already pointed out in the comments, in order to get help with the performance problem you need to add more information and code (e. g. the classes OntModel
and SymmetricProperty
). However in my opinion there is still a lot you can improve in the already available code to make it worth a review. Please add more code to get further suggestions as performance improvements.
add a comment |Â
up vote
2
down vote
Design
You have implemented the class as a singleton, but made the constructor public. That makes the use of the singleton pattern kind of useless. Since you want the class to only be instantiated once, which is inside the class itself, you should make it private
.
public ArrayList<SimilarityModel> getRelatums(String keyword)
Especially in the API of a class, i. e. its public members like this method, you should use interfaces or abstract types, rather than specific implementations. If you replace ArrayList<SimilarityModel>
with List<SimilarityModel>
, you can use any implementation of List
that you like, without having to change many parts of your code.
Style
The Java convention for class names is UpperCamelCase
. ontologyConnector
should be OntologyConnector
.
Your names are not only inconsistent in capitalization, but also abbreviation. OntModel
should be written out as OntologyModel
, to fit with OntologyConnector
but also because abbreviations sometimes force the reader to guess what it means and thus destroy the code's readability.
public ArrayList<SimilarityModel> getRelatums(String keyword)
The return type suggests that the method returns a collection of SimilarityModel
s, but is named getRelatums
. It should be called getSimilarityModels
, if that's what it is actually doing. If not, then the name of the type SimilarityModel
might be chosen badly.
As others have already pointed out in the comments, in order to get help with the performance problem you need to add more information and code (e. g. the classes OntModel
and SymmetricProperty
). However in my opinion there is still a lot you can improve in the already available code to make it worth a review. Please add more code to get further suggestions as performance improvements.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Design
You have implemented the class as a singleton, but made the constructor public. That makes the use of the singleton pattern kind of useless. Since you want the class to only be instantiated once, which is inside the class itself, you should make it private
.
public ArrayList<SimilarityModel> getRelatums(String keyword)
Especially in the API of a class, i. e. its public members like this method, you should use interfaces or abstract types, rather than specific implementations. If you replace ArrayList<SimilarityModel>
with List<SimilarityModel>
, you can use any implementation of List
that you like, without having to change many parts of your code.
Style
The Java convention for class names is UpperCamelCase
. ontologyConnector
should be OntologyConnector
.
Your names are not only inconsistent in capitalization, but also abbreviation. OntModel
should be written out as OntologyModel
, to fit with OntologyConnector
but also because abbreviations sometimes force the reader to guess what it means and thus destroy the code's readability.
public ArrayList<SimilarityModel> getRelatums(String keyword)
The return type suggests that the method returns a collection of SimilarityModel
s, but is named getRelatums
. It should be called getSimilarityModels
, if that's what it is actually doing. If not, then the name of the type SimilarityModel
might be chosen badly.
As others have already pointed out in the comments, in order to get help with the performance problem you need to add more information and code (e. g. the classes OntModel
and SymmetricProperty
). However in my opinion there is still a lot you can improve in the already available code to make it worth a review. Please add more code to get further suggestions as performance improvements.
Design
You have implemented the class as a singleton, but made the constructor public. That makes the use of the singleton pattern kind of useless. Since you want the class to only be instantiated once, which is inside the class itself, you should make it private
.
public ArrayList<SimilarityModel> getRelatums(String keyword)
Especially in the API of a class, i. e. its public members like this method, you should use interfaces or abstract types, rather than specific implementations. If you replace ArrayList<SimilarityModel>
with List<SimilarityModel>
, you can use any implementation of List
that you like, without having to change many parts of your code.
Style
The Java convention for class names is UpperCamelCase
. ontologyConnector
should be OntologyConnector
.
Your names are not only inconsistent in capitalization, but also abbreviation. OntModel
should be written out as OntologyModel
, to fit with OntologyConnector
but also because abbreviations sometimes force the reader to guess what it means and thus destroy the code's readability.
public ArrayList<SimilarityModel> getRelatums(String keyword)
The return type suggests that the method returns a collection of SimilarityModel
s, but is named getRelatums
. It should be called getSimilarityModels
, if that's what it is actually doing. If not, then the name of the type SimilarityModel
might be chosen badly.
As others have already pointed out in the comments, in order to get help with the performance problem you need to add more information and code (e. g. the classes OntModel
and SymmetricProperty
). However in my opinion there is still a lot you can improve in the already available code to make it worth a review. Please add more code to get further suggestions as performance improvements.
answered Feb 28 at 15:05
Raimund Krämer
1,808321
1,808321
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188493%2fretrieving-synonyms-from-an-ontology%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Where can I download the executable project? Where does the
OntModel
class come from? Why don't you follow the Java naming conventions ? Who is forcing you into the uglyIterator
API instead of the nice and modernfor (obj : iterable)
? You should answer all these questions in your post. Just edit it.â Roland Illig
Feb 28 at 4:27
I agree that the question needs to be improved, e. g. with an explanation of what it does. But can anyone explain to me how the downvotes are justified? To me, this does not look like a bad question, and neither an off-topic one.
â Raimund Krämer
Feb 28 at 11:24
Also, @RolandIllig, aren't the ugly Iterator API and the bad naming style what the review answers should be about, rather than being answered by the asker?
â Raimund Krämer
Feb 28 at 11:26
@RaimundKrämer my ontology retrieves related terms when i search a keyword. Primarily, my code do well but when my ontology is growing, then retriving process becomes slow. That is the problem what i am facing with above mentioned code.
â Tolga
Feb 28 at 13:19
1
@Tolga Please add the explanation to the question by editing it, rather than in a comment. Also, the explanation should go into more detail, and it would help a lot if you would add more code to your question, for example the classes
OntModel
,SymmetricProperty
and others. There is a lot in your code that is worth a review, but the performance problem lies most likely somewhere else in your code, if at all.â Raimund Krämer
Feb 28 at 14:52