Skip to content

Commit

Permalink
Add entities list in repository serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
dougppaz committed Jun 27, 2018
1 parent 628ed58 commit b671312
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions bothub/api/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Meta:
'description',
'is_private',
'intents',
'entities',
'examples__count',
'authorization',
'ready_for_train',
Expand Down
7 changes: 7 additions & 0 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def intents(self):
'intent',
flat=True)))

@property
def entities(self):
return list(set(self.examples().annotate(
entities_count=models.Count(
'entities')).filter(entities_count__gte=1).values_list(
'entities__entity', flat=True)))

def examples(self, language=None, deleted=True, queryset=None):
if queryset is None:
queryset = RepositoryExample.objects
Expand Down
15 changes: 15 additions & 0 deletions bothub/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,21 @@ def test_intents(self):
'bye',
self.repository.intents)

def test_entities(self):
example = RepositoryExample.objects.create(
repository_update=self.repository.current_update(
languages.LANGUAGE_EN),
text='my name is Douglas')
RepositoryExampleEntity.objects.create(
repository_example=example,
start=11,
end=18,
entity='name')

self.assertIn(
'name',
self.repository.entities)


class RepositoryExampleTestCase(TestCase):
def setUp(self):
Expand Down

0 comments on commit b671312

Please sign in to comment.