Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation search #287

Merged
merged 20 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/bdc_dbgap_data_dicts.tar.gz
Binary file not shown.
13 changes: 0 additions & 13 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ services:
depends_on:
- elasticsearch
- redis
- nboost
restart: always
networks:
- dug-network
Expand Down Expand Up @@ -87,18 +86,6 @@ services:
ports:
- '6379:6379'

#################################################################################
##
## A scalable, search-engine-boosting platform for developing models to improve
## search results.
##
#################################################################################
nboost:
image: koursaros/nboost:0.3.9-pt
networks:
- dug-network
ports:
- '8000:8000'

networks:
dug-network:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pyrsistent==0.17.3
pytest
pytz==2021.1
PyYAML==6.0
redis==4.4.2
requests==2.28.2
redis==4.4.4
requests==2.31.0
requests-cache==0.9.8
six==1.16.0

Expand Down
2 changes: 1 addition & 1 deletion src/dug/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.9.8dev"
__version__ = "2.9.9dev"
5 changes: 1 addition & 4 deletions src/dug/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def from_env(cls):
"elastic_password": "ELASTIC_PASSWORD",
"redis_host": "REDIS_HOST",
"redis_port": "REDIS_PORT",
"redis_password": "REDIS_PASSWORD",
"nboost_host": "NBOOST_API_HOST",
"nboost_port": "NBOOST_API_PORT"
"redis_password": "REDIS_PASSWORD"
}

kwargs = {}
Expand All @@ -107,5 +105,4 @@ def from_env(cls):
env_value = os.environ.get(env_var)
if env_value:
kwargs[kwarg] = env_value

return cls(**kwargs)
23 changes: 14 additions & 9 deletions src/dug/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging
import os
import sys
Expand All @@ -10,7 +11,6 @@
from dug.core.loaders.network_loader import load_from_network

from dug import hookspecs
from dug.config import Config
from dug.core import parsers
from dug.core.factory import DugFactory
from dug.core.parsers import DugConcept, Parser, get_parser
Expand Down Expand Up @@ -50,6 +50,11 @@ def __init__(self, factory: DugFactory):
self._search = self._factory.build_search_obj(indices=[
self.concepts_index, self.variables_index, self.kg_index
])
self._index = self._factory.build_indexer_obj(
indices=[
self.concepts_index, self.variables_index, self.kg_index
]
)

def crawl(self, target_name: str, parser_type: str, element_type: str = None):

Expand All @@ -71,36 +76,36 @@ def _crawl(self, target: Path, parser: Parser, element_type):
for element in crawler.elements:
# Only index DugElements as concepts will be indexed differently in next step
if not isinstance(element, DugConcept):
self._search.index_element(element, index=self.variables_index)
self._index.index_element(element, index=self.variables_index)

# Index Annotated/TranQLized Concepts and associated knowledge graphs
for concept_id, concept in crawler.concepts.items():
self._search.index_concept(concept, index=self.concepts_index)
self._index.index_concept(concept, index=self.concepts_index)

# Index knowledge graph answers for each concept
for kg_answer_id, kg_answer in concept.kg_answers.items():
self._search.index_kg_answer(concept_id=concept_id,
self._index.index_kg_answer(concept_id=concept_id,
kg_answer=kg_answer,
index=self.kg_index,
id_suffix=kg_answer_id)

def search(self, target, query, **kwargs):
event_loop = asyncio.get_event_loop()
targets = {
'concepts': partial(
self._search.search_concepts, index=kwargs.get('index', self.concepts_index)),
'variables': partial(
self._search.search_variables, index=kwargs.get('index', self.variables_index), concept=kwargs.pop('concept', None)),
'kg': partial(
self._search.search_kg, index=kwargs.get('index', self.kg_index), unique_id=kwargs.pop('unique_id', None)),
'nboost': partial(
self._search.search_nboost, index=kwargs.get('index', None)),
self._search.search_kg, index=kwargs.get('index', self.kg_index), unique_id=kwargs.pop('unique_id', None))
}
kwargs.pop('index', None)
func = targets.get(target)
if func is None:
raise ValueError(f"Target must be one of {', '.join(targets.keys())}")

return func(query=query, **kwargs)
results = event_loop.run_until_complete(func(query=query, **kwargs))
event_loop.run_until_complete(self._search.es.close())
return results

def status(self):
...
Loading