ontology_search.rb revision c0db3f29bc01c8d672cf19648b1172dd8d21d2d4
0e126d3cc0f2cb6141106843ebff09c67f75bff8Daniel Couto Valerequire 'json'
0e126d3cc0f2cb6141106843ebff09c67f75bff8Daniel Couto Vale
a72767dfae41be032792284ef42c3a12a45aa4fdEileen Bolloff#
3dc5cf7d5b8a1b07204e85997595907de39df819Eileen Bolloff# Beware! This is not tested well.
d4dfdee51766940878e289b8590594a598f5b0e1Eileen Bolloff#
3dc5cf7d5b8a1b07204e85997595907de39df819Eileen Bolloffclass OntologySearch
3dc5cf7d5b8a1b07204e85997595907de39df819Eileen Bolloff
3dc5cf7d5b8a1b07204e85997595907de39df819Eileen Bolloff class Response < Struct.new(:page,:ontologiesPerPage,:ontologiesInSet,:ontologies)
a72767dfae41be032792284ef42c3a12a45aa4fdEileen Bolloff end
a72767dfae41be032792284ef42c3a12a45aa4fdEileen Bolloff
b479f88ab203603ad81cad637cad3b1050184bf2Daniel Couto Vale def initialize
a72767dfae41be032792284ef42c3a12a45aa4fdEileen Bolloff @limit = 20
b479f88ab203603ad81cad637cad3b1050184bf2Daniel Couto Vale end
3dc5cf7d5b8a1b07204e85997595907de39df819Eileen Bolloff
4abcc3febd724b202d60bd92a1a9052c02b9eb03Eileen Bolloff def make_repository_keyword_list_json(repository, prefix)
3dc5cf7d5b8a1b07204e85997595907de39df819Eileen Bolloff JSON.generate(make_repository_keyword_list(repository, prefix))
1115fd7e3171f7aaeb98472789edf016996b7278henning mueller end
3dc5cf7d5b8a1b07204e85997595907de39df819Eileen Bolloff
37ae8a21cfb5b55050c025d1b23aabaf841bd301Eileen Bolloff def make_global_keyword_list_json(prefix)
f71f4d86365be9f6eea0b441455fbfd686f43cd4Eileen Bolloff JSON.generate(make_global_keyword_list(prefix))
f71f4d86365be9f6eea0b441455fbfd686f43cd4Eileen Bolloff end
c3960e37f5f7b3881e4ac90cc1aa61c97222d2c5Daniel Couto Vale
1115fd7e3171f7aaeb98472789edf016996b7278henning mueller def make_repository_keyword_list(repository, prefix)
37ae8a21cfb5b55050c025d1b23aabaf841bd301Eileen Bolloff text_list = Set.new
25e680b4f0bbd68678787e4d349bc99e23ee0c73Eileen Bolloff
25e680b4f0bbd68678787e4d349bc99e23ee0c73Eileen Bolloff #unless repository.ontologies.where("name = :prefix", prefix: prefix, repository_id: repository).empty?
1115fd7e3171f7aaeb98472789edf016996b7278henning mueller # text_list.add(prefix)
37ae8a21cfb5b55050c025d1b23aabaf841bd301Eileen Bolloff #end
f71f4d86365be9f6eea0b441455fbfd686f43cd4Eileen Bolloff
f71f4d86365be9f6eea0b441455fbfd686f43cd4Eileen Bolloff repository.ontologies.select(:name).where("name ILIKE :prefix", prefix: "#{prefix}%").limit(25).group("name").limit(5).each do |ontology|
7e93ca8c8fcef80ae943587eea6b7de288249f97Daniel Couto Vale text_list.add(ontology.name)
3a2e1a2642136a6e39213b7bd635c81736df7d10Daniel Couto Vale end
37ae8a21cfb5b55050c025d1b23aabaf841bd301Eileen Bolloff
25e680b4f0bbd68678787e4d349bc99e23ee0c73Eileen Bolloff Entity.collect_keywords(prefix, repository).each do |symbol|
25e680b4f0bbd68678787e4d349bc99e23ee0c73Eileen Bolloff text_list.add(symbol.display_name) if symbol.display_name
3a2e1a2642136a6e39213b7bd635c81736df7d10Daniel Couto Vale text_list.add(symbol.name) if symbol.name
37ae8a21cfb5b55050c025d1b23aabaf841bd301Eileen Bolloff text_list.add(symbol.text) if symbol.text
25e680b4f0bbd68678787e4d349bc99e23ee0c73Eileen Bolloff end
25e680b4f0bbd68678787e4d349bc99e23ee0c73Eileen Bolloff
4abcc3febd724b202d60bd92a1a9052c02b9eb03Eileen Bolloff ontology_ids = Set.new
1115fd7e3171f7aaeb98472789edf016996b7278henning mueller repository.ontologies.select(:id).each do |ontology|
c28fc8aa2cdf7f9c9ae76899354350473d155981Eugen Kuksa ontology_ids.add(ontology.id)
c28fc8aa2cdf7f9c9ae76899354350473d155981Eugen Kuksa end
bd63e05633307b60a7216b523b2b7a2bcc7b2823Eugen Kuksa
c28fc8aa2cdf7f9c9ae76899354350473d155981Eugen Kuksa Logic.where("name ILIKE :prefix", prefix: "#{prefix}%").limit(5).each do |logic|
0e126d3cc0f2cb6141106843ebff09c67f75bff8Daniel Couto Vale logic_ontology_ids = Set.new
logic.ontologies.each do |ontology|
logic_ontology_ids.add(ontology.id)
end
if (ontology_ids & logic_ontology_ids).size != 0
text_list.add(logic.name)
end
end
text_list.to_a.sort.map { |x| {text: x} }
end
def make_global_keyword_list(prefix)
text_list = Set.new
text_list.add(prefix)
text_list.to_a.sort.map { |x| {text: x} }
end
def make_bean_list_json(repository, keyword_list, page)
JSON.generate(make_bean_list_response(repository, keyword_list, page))
end
def select_item_list(keyword_list, type_name)
item_list = Array.new
keyword_list.each do |keyword|
if keyword["type"] == type_name
item_list.push keyword["item"]
end
end
item_list
end
def select_item(keyword_list, type_name, type)
keyword_list.each do |keyword|
if keyword["type"] == type_name
if keyword["item"].nil?
return nil
else
return type.find_by_id(keyword["item"].to_i)
end
end
end
nil
end
def make_bean_list_response(repository, keyword_list, page)
mixed_list = select_item_list(keyword_list, 'Mixed')
ontology_type = select_item(keyword_list, 'OntologyType', OntologyType)
project = select_item(keyword_list, 'Project', Project)
formality_level = select_item(keyword_list, 'FormalityLevel', FormalityLevel)
license_model = select_item(keyword_list, 'LicenseModel', LicenseModel)
task = select_item(keyword_list, 'Task', Task)
bean_list_factory = OntologyBeanListFactory.new
search = Ontology.search_by_keywords(mixed_list, page, repository, nil, ontology_type, formality_level, license_model, task)
search.results.each do |ontology|
bean_list_factory.add_small_bean(ontology)
end
Response.new(page, @limit, search.total, bean_list_factory.bean_list)
end
end