def test_vector_builder(self):
     vectors = VectorBuilder(Entry.objects.all(),
                             ['title', 'excerpt', 'content'])
     params = {
         'title': 'My entry 1',
         'content': 'This is my first content',
         'tags': 'zinnia, test',
         'slug': 'my-entry-1'
     }
     Entry.objects.create(**params)
     params = {
         'title': 'My entry 2',
         'content': 'My second entry',
         'tags': 'zinnia, test',
         'slug': 'my-entry-2'
     }
     Entry.objects.create(**params)
     columns, dataset = vectors()
     self.assertEqual(
         sorted(columns),
         sorted(
             ['content', 'This', 'my', 'is', '1', 'second', '2', 'first']))
     self.assertEqual(
         sorted([sorted(row) for row in dataset.values()]),
         sorted([
             sorted([1, 1, 1, 1, 1, 0, 0, 1]),
             sorted([0, 0, 0, 0, 0, 1, 1, 0])
         ]))
Beispiel #2
0
 def test_vector_builder(self):
     vectors = VectorBuilder({'queryset': Entry.objects.all(),
                              'fields': ['title', 'excerpt', 'content']})
     params = {'title': 'My entry 1', 'content':
               'This is my first content',
               'tags': 'zinnia, test', 'slug': 'my-entry-1'}
     Entry.objects.create(**params)
     params = {'title': 'My entry 2', 'content':
               'My second entry',
               'tags': 'zinnia, test', 'slug': 'my-entry-2'}
     Entry.objects.create(**params)
     columns, dataset = vectors()
     self.assertEquals(columns, ['content', 'This', 'my', 'is', '1',
                                 'second', '2', 'first'])
     self.assertEquals(dataset.values(), [[1, 1, 1, 1, 1, 0, 0, 1],
                                          [0, 0, 0, 0, 0, 1, 1, 0]])
 def test_vector_builder(self):
     vectors = VectorBuilder(Entry.objects.all(),
                             ['title', 'excerpt', 'content'])
     params = {
         'title': 'My entry 1',
         'content': 'This is my first content',
         'tags': 'zinnia, test',
         'slug': 'my-entry-1'
     }
     Entry.objects.create(**params)
     params = {
         'title': 'My entry 2',
         'content': 'My second entry',
         'tags': 'zinnia, test',
         'slug': 'my-entry-2'
     }
     Entry.objects.create(**params)
     columns, dataset = vectors()
     #The ordering of columns is dependent on the order that a dictionary's
     #keys were iterated through (words_total.items, to be specific)
     #, which is undefined. Therefore, we cannot rely on its order being
     #fixed. So, I just sort the list to get it in a consistant order
     self.assertEqual(
         sorted(columns),
         sorted(
             ['content', 'This', 'my', 'is', '1', 'second', '2', 'first']))
     #Again, we can't rely on the ordering of dict contents
     #being constant. I *think* I've addressed all of
     #the sorting issues, but I might have missed something.
     #If the vectorbuilder needs ordering to matter,
     #the algorithm used needs to be changed significantly.
     self.assertEqual(
         sorted([sorted(row) for row in dataset.values()]),
         sorted([
             sorted([1, 1, 1, 1, 1, 0, 0, 1]),
             sorted([0, 0, 0, 0, 0, 1, 1, 0])
         ]))
Beispiel #4
0
from zinnia.models import Entry
from zinnia.models import Author
from zinnia.models import Category
from zinnia.managers import DRAFT
from zinnia.managers import tags_published
from zinnia.managers import PINGBACK, TRACKBACK
from zinnia.settings import PROTOCOL
from zinnia.comparison import VectorBuilder
from zinnia.comparison import pearson_score
from zinnia.templatetags.zcalendar import ZinniaCalendar
from zinnia.templatetags.zbreadcrumbs import retrieve_breadcrumbs

register = Library()

VECTORS = None
VECTORS_FACTORY = lambda: VectorBuilder(Entry.published.all(),
                                        ['title', 'excerpt', 'content'])
CACHE_ENTRIES_RELATED = {}


@register.inclusion_tag('zinnia/tags/dummy.html')
def get_categories(template='zinnia/tags/categories.html'):
    """Return the categories"""
    return {'template': template, 'categories': Category.objects.all()}


@register.inclusion_tag('zinnia/tags/dummy.html')
def get_authors(template='zinnia/tags/authors.html'):
    """Return the published authors"""
    return {'template': template, 'authors': Author.published.all()}

Beispiel #5
0
from django.contrib.comments.models import Comment
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import smart_unicode

from zinnia.models import Entry
from zinnia.models import Author
from zinnia.models import Category
from zinnia.comparison import VectorBuilder
from zinnia.comparison import pearson_score
from zinnia.templatetags.zbreadcrumbs import retrieve_breadcrumbs

register = Library()

VECTORS = None
VECTORS_FACTORY = lambda: VectorBuilder({'queryset': Entry.published.all(),
                                         'fields': ['title', 'excerpt',
                                                    'content']})
CACHE_ENTRIES_RELATED = {}


@register.inclusion_tag('zinnia/tags/dummy.html')
def get_categories(template='zinnia/tags/categories.html'):
    """Return the categories"""
    return {'template': template,
            'categories': Category.tree.all()}


@register.inclusion_tag('zinnia/tags/dummy.html')
def get_authors(template='zinnia/tags/authors.html'):
    """Return the published authors"""
    return {'template': template,