Skip to content

Commit

Permalink
structuring search module
Browse files Browse the repository at this point in the history
  • Loading branch information
litmanowicziv committed Aug 22, 2022
1 parent fbee64c commit 096a60a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 40 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the Software), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 1 addition & 1 deletion entities/Article.py → search/Article.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from entities.Doc import Doc
from search.Doc import Doc


class Article(Doc):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion entities/Review.py → search/Review.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from datetime import datetime
from entities.Doc import Doc
from search.Doc import Doc


class Review(Doc):
Expand Down
39 changes: 2 additions & 37 deletions search_engine.py → search/SearchEngine.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import os.path as path
import sys
import glob
import xml.etree.ElementTree as ET

from entities.Article import *
from entities.Review import *
from entities.Word import *
from .Doc import *
from .Word import *


class SearchEngine:
Expand Down Expand Up @@ -71,32 +65,3 @@ def most_common(self, n:int):
sorted_words = sorted(self.invert_tbl.values(), key=lambda word: word.total, reverse=True)
sorted_words = [(word.key, word.total) for word in sorted_words]
return sorted_words[:n]


if __name__ == '__main__':

search_engine = SearchEngine(stopwords=path.abspath(sys.argv[1]))

# ./Corpus/sgml/reut2-00*.xml
# for file in sorted(glob.glob(path.abspath(sys.argv[2]))):
# print(file)
# root = ET.parse(file).getroot()
# for article_xml in root.findall('REUTERS'):
# article = Article(article_xml.get('NEWID'), article_xml)
# search_engine.add(article)

# ./Corpus/review_data.txt
lines = open(path.abspath(sys.argv[2])).readlines()
for count, line in enumerate(lines):
review = Review(count, line)
search_engine.add(review)

search_words = ["Great", "product", "love", "happy"]
for word in search_words:
search_res = search_engine.search(word, 5)
print("{:20} : {:4} results.".format(word, len(search_res)))
print("\n".join(search_res))

print("Most Common Words")
for word, num_results in search_engine.most_common(10):
print("{:20} : {} results".format(word, num_results))
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from setuptools import setup

setup(
name='search-engine',
version='1.0.0',
author='Ziv Litmanowicz',
license='MIT',
description='A library for dealing with splittable files',
packages=['search'],
url='https://github.com/litmanowicziv/search-engine',
keywords=['search engine', 'text analysis'],
classifiers=[
'Intended Audience :: Developers',
],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*',
)
2 changes: 1 addition & 1 deletion tests/TestDoc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from entities.Doc import *
from search.Doc import *


class TestDoc(unittest.TestCase):
Expand Down

0 comments on commit 096a60a

Please sign in to comment.