|
|
|
@ -3,7 +3,38 @@ from flask import Flask, render_template, jsonify |
|
|
|
from collections import defaultdict |
|
|
|
import os |
|
|
|
import json |
|
|
|
import re |
|
|
|
import wordninja |
|
|
|
from typing import List, Set |
|
|
|
|
|
|
|
class CustomWordNinja: |
|
|
|
def __init__(self, custom_words: List[str] = None): |
|
|
|
self.custom_words = [] |
|
|
|
if custom_words: |
|
|
|
# Store custom words with original capitalization, sorted by length |
|
|
|
self.custom_words = sorted(custom_words, key=len, reverse=True) |
|
|
|
|
|
|
|
def split(self, text: str) -> str: |
|
|
|
working_text = text |
|
|
|
|
|
|
|
# First handle exact custom words to preserve capitalization |
|
|
|
for word in self.custom_words: |
|
|
|
pattern = re.compile(word, re.IGNORECASE) |
|
|
|
working_text = pattern.sub(f' {word} ', working_text) |
|
|
|
|
|
|
|
# Clean up spaces |
|
|
|
working_text = ' '.join(working_text.split()) |
|
|
|
|
|
|
|
# For remaining text, use wordninja |
|
|
|
parts = [] |
|
|
|
for part in working_text.split(): |
|
|
|
if part in self.custom_words: |
|
|
|
parts.append(part) |
|
|
|
else: |
|
|
|
split_parts = wordninja.split(part) |
|
|
|
parts.extend(split_parts) |
|
|
|
|
|
|
|
return ' '.join(parts) |
|
|
|
|
|
|
|
POKEMON_PROPER_NOUNS = { |
|
|
|
"Alola", |
|
|
|
@ -124,6 +155,8 @@ def load_pokemon_data(): |
|
|
|
@app.route('/') |
|
|
|
def index(): |
|
|
|
pokemon_list = load_pokemon_data() |
|
|
|
|
|
|
|
splitter = CustomWordNinja(POKEMON_PROPER_NOUNS) |
|
|
|
|
|
|
|
try: |
|
|
|
with open('efficiency_plan.json', 'r', encoding='utf-8') as f: |
|
|
|
@ -142,9 +175,8 @@ def index(): |
|
|
|
direct = cursor.fetchone() |
|
|
|
|
|
|
|
if direct: |
|
|
|
words = wordninja.split(direct[0]) |
|
|
|
cleaned_method = ' '.join(words) |
|
|
|
return [cleaned_method] |
|
|
|
words = splitter.split(direct[0]) |
|
|
|
return [words] |
|
|
|
|
|
|
|
# Try to find indirect evolution path |
|
|
|
cursor.execute(''' |
|
|
|
@ -174,9 +206,8 @@ def index(): |
|
|
|
cleaned_methods = [] |
|
|
|
for method in methods: |
|
|
|
# Split and rejoin with spaces |
|
|
|
words = wordninja.split(method[0]) |
|
|
|
cleaned_method = ' '.join(words) |
|
|
|
cleaned_methods.append(cleaned_method) |
|
|
|
words = splitter.split(method[0]) |
|
|
|
cleaned_methods.append(words) |
|
|
|
return cleaned_methods |
|
|
|
return ['Evolution'] |
|
|
|
|
|
|
|
@ -238,12 +269,6 @@ def pokemon_details(pfic): |
|
|
|
return jsonify(encounters) |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
# Add the custom words to wordninja's word list |
|
|
|
#wordninja.DEFAULT_WEIGHT_MULTIPLIER = 2 # Make default words twice as likely |
|
|
|
#for word in POKEMON_PROPER_NOUNS: |
|
|
|
# wordninja.addWords([word], weight=10) # Higher weight makes these words more likely to be kept together |
|
|
|
|
|
|
|
|
|
|
|
extra_files = ['.'] |
|
|
|
extra_dirs = ['./templates/', './static/'] |
|
|
|
for extra_dir in extra_dirs: |
|
|
|
|