def testAutocomplete1():
    data = Suggestions.load()
    autocomplete = Autocomplete1(data)

    results = autocomplete.performSearch('biology')

    expectedPath = path.dirname(__file__) + '/expected/autocomplete1_expected.json'
    with open(expectedPath, 'r') as f:
        expected = json.load(f)

    assert len(results) == 15
    assert results[0] == expected
def testAutocomplete3():
    data = Suggestions.load()
    autocomplete = Autocomplete3(data)

    results = autocomplete.performSearch('BIOLOGY')

    expectedPath = path.dirname(
        __file__) + '/expected/autocomplete3_expected.json'
    with open(expectedPath, 'r') as f:
        expected = json.load(f)

    assert len(results) == 29
    assert results[1] == expected[0]
    assert results[3] == expected[1]
Ejemplo n.º 3
0
 def __build_graph(self, term, depth=0):
     if depth == self.MAX_DEPTH:
         return
     suggestions = Suggestions(term).get_suggestion()
     for suggestion in suggestions:
         if ' vs ' not in suggestion:
             continue
         if suggestion.count(' vs ') > 1:
             continue
         a, b = suggestion.split(' vs ')
         a = a.lower()
         b = b.lower()
         if b not in self.__nodes:
             self.__nodes.append(b)
             edge = (a, b)
             rev_edge = (b, a)
             if edge not in self.__edges and rev_edge not in self.__edges:
                 self.__edges.append(edge)
             self.__build_graph(b, depth=depth + 1)
Ejemplo n.º 4
0
    def __build_graph(self, term, depth=0):
        if depth == self.MAX_DEPTH:
            return

        suggestions = Suggestions(term).get_suggestions()

        for suggestion in suggestions:
            if not suggestion.count(' vs ') == 1:
                continue

            first_word, second_word = suggestion.split(' vs ')
            if second_word not in self.__nodes:
                self.__nodes.append(second_word)
                edge = (first_word, second_word)
                if edge not in self.__edges and tuple(
                        reversed(edge)) not in self.__edges:
                    self.__edges.append(edge)

                self.__build_graph(second_word, depth=depth + 1)
Ejemplo n.º 5
0
import suggestions
import json
import create_csv
from flask import Flask, request, jsonify, render_template, url_for
from flask_cors import CORS
from meta_handler import MetaHandler
from suggestions import Suggestions


meta_handler = MetaHandler()
sugg = Suggestions(meta_handler)
app = Flask(__name__)
CORS(app)

# create & load csv
create_csv.aggregate_csv_data(meta_handler, overwrite=False)
results = create_csv.load_csv()


# --- define routes ---

@app.route('/', methods=['GET'])
def index():
    suggs = sugg.get_top_users(results, 20)

    return render_template('index.html', users=json.dumps(suggs))


@app.route('/suggestions', methods=['POST'])
def get_suggestions():
    res = sugg.get_suggestions(results, request.form)
Ejemplo n.º 6
0
 def test_parse_of_content(self):
     content = b'<?xml version="1.0"?><toplevel><CompleteSuggestion><suggestion data="hristiyan vs m\xfcsl\xfcman"/></CompleteSuggestion><CompleteSuggestion><suggestion data="islamiyet ve hristiyanl&#x131;k"/></CompleteSuggestion><CompleteSuggestion><suggestion data="yahudi vs hristiyan"/></CompleteSuggestion><CompleteSuggestion><suggestion data="m\xfcsl\xfcman vs hristiyan futbolcular"/></CompleteSuggestion></toplevel>'
     Suggestions.get_element_tree(content)