ontology_search.rb revision 7c3015ea0cd129c0bbbf3a3cc4b35585d24b248d
1516N/Arequire 'json'
154N/A
154N/Aclass OntologySearch
154N/A
154N/A def initialize()
154N/A end
154N/A
154N/A def makeKeywordListJson(prefix)
154N/A keywordList = makeKeywordList(prefix)
154N/A return JSON.generate(keywordList)
154N/A end
154N/A
154N/A def makeKeywordList(prefix)
154N/A textList = Set.new
154N/A textList.add(prefix) unless Ontology.where("name = :prefix", prefix: prefix).length == 0
154N/A textList.add(prefix) unless Entity.where("name = :prefix", prefix: prefix).length == 0
409N/A Ontology.select(:name).where("name LIKE :prefix", prefix: "#{prefix}%").group("name").limit(50).each do |ontology|
409N/A textList.add(ontology.name)
154N/A end
154N/A Entity.select(:name).where("name LIKE :prefix", prefix: "#{prefix}%").group("name").limit(50).each do |symbol|
154N/A textList.add(symbol.name)
154N/A end
3158N/A textList = textList.to_a();
154N/A textList = textList.sort
1715N/A keywordListFactory = KeywordListFactory.new()
1715N/A textList.each do |text|
1715N/A keywordListFactory.addKeyword(text)
1715N/A end
1715N/A keywordList = keywordListFactory.getKeywordList()
526N/A return keywordList
154N/A end
154N/A
2721N/A def makeBeanListJson(keywordList)
2721N/A beanList = makeBeanList(keywordList)
154N/A return JSON.generate(beanList)
430N/A end
154N/A
2721N/A def makeBeanList(keywordList)
2721N/A ontologyHash = Hash.new
2721N/A index = 0
2721N/A keywordList.each do |keyword|
2983N/A keywordHash = Hash.new
2983N/A Ontology.where("name = :name", name: "#{keyword}").limit(50).each do |ontology|
2721N/A if (keywordHash[ontology.id].nil?)
2721N/A keywordHash[ontology.id] = ontology
2721N/A end
2721N/A end
2721N/A Entity.where("name = :name", name: "#{keyword}").limit(50).each do |symbol|
2721N/A if (keywordHash[symbol.ontology.id].nil?)
2721N/A keywordHash[symbol.ontology.id] = symbol.ontology
2721N/A end
2721N/A end
154N/A if (index == 0)
2721N/A ontologyHash = keywordHash
2721N/A else
158N/A hash = Hash.new
2721N/A keywordHash.each_key do |key|
2721N/A if (!ontologyHash[key].nil?)
2721N/A hash[key] = ontologyHash[key]
2721N/A end
2721N/A end
2721N/A ontologyHash = hash
1185N/A end
2721N/A index = index + 1
2721N/A end
154N/A beanListFactory = OntologyBeanListFactory.new()
2721N/A ontologyHash.each_value do |ontology|
2721N/A beanListFactory.addSmallBean(ontology)
2721N/A end
2721N/A beanList = beanListFactory.getBeanList()
2721N/A return beanList
158N/A end
2721N/A
2721N/Aend
2721N/A