-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
318 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from bothub.common.documents.repositorynlplog import RepositoryNLPLogDocument | ||
from bothub.common.documents.repositoryqanlplog import RepositoryQANLPLogDocument | ||
from bothub.common.documents.repositorybasicexample import RepositoryExampleDocument | ||
|
||
__all__ = ( | ||
"RepositoryNLPLogDocument", | ||
"RepositoryQANLPLogDocument", | ||
"RepositoryExampleDocument" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from django.conf import settings | ||
from django_elasticsearch_dsl import Document, Index, fields | ||
|
||
from bothub.common.models import ( | ||
RepositoryExample, | ||
RepositoryExampleEntity, | ||
RepositoryIntent, | ||
RepositoryVersionLanguage, | ||
) | ||
|
||
REPOSITORYBASICEXAMPLE_INDEX = Index(settings.ELASTICSEARCH_INDEX_NAMES[__name__]) | ||
|
||
|
||
@REPOSITORYBASICEXAMPLE_INDEX.doc_type | ||
class RepositoryExampleDocument(Document): | ||
repository_version_language = fields.ObjectField( | ||
properties={ | ||
"pk": fields.IntegerField(), | ||
"language": fields.TextField(fields={"raw": fields.KeywordField()}), | ||
} | ||
) | ||
intent = fields.ObjectField( | ||
properties={"text": fields.TextField(fields={"raw": fields.KeywordField()})} | ||
) | ||
entities = fields.NestedField( | ||
properties={ | ||
"entity": fields.ObjectField( | ||
properties={ | ||
"value": fields.TextField(fields={"raw": fields.KeywordField()}), | ||
} | ||
), | ||
} | ||
) | ||
pk = fields.IntegerField() | ||
|
||
class Django: | ||
model = RepositoryExample | ||
fields = [ | ||
"id", | ||
"text", | ||
] | ||
related_models = [ | ||
RepositoryVersionLanguage, | ||
RepositoryIntent, | ||
RepositoryExampleEntity, | ||
] | ||
|
||
def get_queryset(self): | ||
return ( | ||
super(RepositoryExampleDocument, self) | ||
.get_queryset() | ||
.select_related( | ||
"repository_version_language", | ||
"intent", | ||
) | ||
.prefetch_related( | ||
"entities", | ||
"translations", | ||
) | ||
) | ||
|
||
def get_instances_from_related(self, related_instance): | ||
if isinstance(related_instance, RepositoryVersionLanguage): | ||
return related_instance.added.all() | ||
elif isinstance(related_instance, RepositoryIntent): | ||
return related_instance.repositoryexample_set.all() | ||
elif isinstance(related_instance, RepositoryExampleEntity): | ||
return related_instance.repository_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.