Skip to content

Commit

Permalink
Remove visualization app (#47)
Browse files Browse the repository at this point in the history
* remove unused files and code

* remove requests from pipfile

* remove required from author in profile

* change create() to update_or_create() if profile has the same id_in_channel and channel
  • Loading branch information
msfernandes authored Jun 29, 2018
1 parent 3931dc7 commit 84d362b
Show file tree
Hide file tree
Showing 74 changed files with 22 additions and 86,542 deletions.
9 changes: 0 additions & 9 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ djangorestframework = "==3.7.7"
django-filter = "*"
django-nested-admin = "*"
gunicorn = "*"
django-compressor = "*"
django-compressor-toolkit = "*"
django-npm = "*"
nltk = "*"
jupyter = "*"
requests = "*"
pprint = "*"
jsonfield = "*"
click = "*"

[requires]
python_version = "3.6"
3,293 changes: 0 additions & 3,293 deletions jupyter/WordCloud.ipynb

This file was deleted.

8 changes: 0 additions & 8 deletions nltk_data.py

This file was deleted.

6 changes: 5 additions & 1 deletion src/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ class Meta:
verbose_name_plural = _('profiles')

def __str__(self):
return '%s <%s>' % (self.author.name, self.channel.name)
if self.author:
profile_name = '%s <%s>' % (self.author.name, self.channel.name)
else:
profile_name = '%s <%s>' % (self.id_in_channel, self.channel.name)
return profile_name


class ProfileAttribute(model_mixings.AttributeMixing):
Expand Down
5 changes: 0 additions & 5 deletions src/apps/core/processors.py

This file was deleted.

22 changes: 17 additions & 5 deletions src/apps/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ProfileSerializer(serializers.HyperlinkedModelSerializer):
)
author_id = serializers.PrimaryKeyRelatedField(
queryset=models.Author.objects.all(),
write_only=True, source='author')
write_only=True, source='author', required=False)
channel = serializers.HyperlinkedRelatedField(
read_only=True,
view_name='channel-detail'
Expand All @@ -142,10 +142,22 @@ def create(self, validated_data):
domain_attrs = models.ProfileDomainAttribute.objects.filter(
channel=validated_data['channel'])
if validate_attrs(domain_attrs, attrs_data):
profile = models.Profile.objects.create(**validated_data)
for attr in attrs_data:
models.ProfileAttribute.objects.create(
profile=profile, **attr)
channel = validated_data.pop('channel')
id_in_channel = validated_data.pop('id_in_channel')
profile, created = models.Profile.objects.update_or_create(
channel=channel, id_in_channel=id_in_channel,
defaults=validated_data)
for attr_data in attrs_data:
if created:
models.ProfileAttribute.objects.create(
profile=profile, **attr_data)
else:
attr = models.ProfileAttribute.objects.get_or_create(
profile=profile,
field=attr_data['field']
)[0]
attr.value = attr_data['value']
attr.save()
return profile

def update(self, instance, validated_data):
Expand Down
49 changes: 0 additions & 49 deletions src/apps/core/signals.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,10 @@
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.db import transaction
from rest_framework.authtoken.models import Token
from apps.core.models import Manifestation
from apps.nlp import models, pre_processing


@receiver(post_save, sender=User)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)


@receiver(post_save, sender=Manifestation)
@transaction.atomic
def process_manifestation(sender, instance, created, **kwargs):
if not created:
models.ManifestationToken.objects.filter(
manifestation=instance
).delete()

bow, stem_reference = pre_processing.bow(instance.content)
if len(bow) > 0:
max_value = max(bow.values())
for stem, occurrences in bow.items():
token = models.Token.objects.get_or_create(stem=stem)[0]
for original_word, occurrences in stem_reference[stem].items():
token.add_original_word(original_word, times=occurrences)
token.save()

mt = models.ManifestationToken()
mt.manifestation = instance
mt.token = token
mt.occurrences = occurrences
mt.frequency = occurrences / max_value
mt.save()
print(mt)

bigram_bow, stem_reference = pre_processing.bow(instance.content, ngrams=2)
if len(bigram_bow) > 0:
max_value = max(bigram_bow.values())
for token, occurrences in bigram_bow.items():
token = models.Token.objects.get_or_create(stem=token)[0]
t1, t2 = token.stem.split()
token.add_original_word(' '.join([
stem_reference[t1].most_common(1)[0][0],
stem_reference[t2].most_common(1)[0][0]
]))
token.bigram = True
token.save()
mt = models.ManifestationToken()
mt.manifestation = instance
mt.token = token
mt.occurrences = occurrences
mt.frequency = occurrences / max_value
mt.save()
print(mt)
1 change: 0 additions & 1 deletion src/apps/nlp/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions src/apps/nlp/apps.py

This file was deleted.

Empty file.
Empty file.
106 changes: 0 additions & 106 deletions src/apps/nlp/management/commands/tokenize_data.py

This file was deleted.

46 changes: 0 additions & 46 deletions src/apps/nlp/migrations/0001_initial.py

This file was deleted.

40 changes: 0 additions & 40 deletions src/apps/nlp/migrations/0002_auto_20180529_1347.py

This file was deleted.

17 changes: 0 additions & 17 deletions src/apps/nlp/migrations/0003_auto_20180604_1601.py

This file was deleted.

18 changes: 0 additions & 18 deletions src/apps/nlp/migrations/0004_token_bigram.py

This file was deleted.

19 changes: 0 additions & 19 deletions src/apps/nlp/migrations/0005_analysis_algorithm.py

This file was deleted.

Loading

0 comments on commit 84d362b

Please sign in to comment.