-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test and refactor WikiCorpus #1821
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
574134e
minor style refactoring and comment fixes in accordance to PEP8
steremma 952e8d5
Created test data in legitimate compressed XML format (.xml.bz2) for …
steremma 7ddce6c
Added test class for the WikiCorpus source.
steremma 836c3c2
Fix python 3 compatibility for generator next method
steremma 43a48f5
code review corrections
steremma 8b7a1d5
Moved WikiCorpus tests from test/test_wikicorpus.py into its class wi…
steremma eeea748
Merge branch 'develop' into test_refactor_wiki
steremma b5976c4
Discarded the empty input test for the WikiCorpus since an empty file…
steremma 78f2870
Added 2 more tests
steremma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# | ||
# Copyright (C) 2010 Radim Rehurek <[email protected]> | ||
# Copyright (C) 2012 Lars Buitinck <[email protected]> | ||
# Copyright (C) 2018 Emmanouil Stergiadis <[email protected]> | ||
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html | ||
|
||
|
||
|
@@ -56,8 +57,8 @@ | |
RE_P12 = re.compile(r'\n(({\|)|(\|-)|(\|}))(.*?)(?=\n)', re.UNICODE) # table formatting | ||
RE_P13 = re.compile(r'\n(\||\!)(.*?\|)*([^|]*?)', re.UNICODE) # table cell formatting | ||
RE_P14 = re.compile(r'\[\[Category:[^][]*\]\]', re.UNICODE) # categories | ||
# Remove File and Image template | ||
RE_P15 = re.compile(r'\[\[([fF]ile:|[iI]mage)[^]]*(\]\])', re.UNICODE) | ||
RE_P15 = re.compile(r'\[\[([fF]ile:|[iI]mage)[^]]*(\]\])', re.UNICODE) # Remove File and Image template | ||
|
||
|
||
# MediaWiki namespaces (https://www.mediawiki.org/wiki/Manual:Namespace) that | ||
# ought to be ignored | ||
|
@@ -332,19 +333,15 @@ def __init__(self, fname, processes=None, lemmatize=utils.has_pattern(), diction | |
self.token_min_len = token_min_len | ||
self.token_max_len = token_max_len | ||
self.lower = lower | ||
|
||
if dictionary is None: | ||
self.dictionary = Dictionary(self.get_texts()) | ||
else: | ||
self.dictionary = dictionary | ||
self.dictionary = dictionary or Dictionary(self.get_texts()) | ||
|
||
def get_texts(self): | ||
""" | ||
Iterate over the dump, returning text version of each article as a list | ||
of tokens. | ||
|
||
Only articles of sufficient length are returned (short articles & redirects | ||
etc are ignored). This is control by `article_min_tokens` on the class instance. | ||
etc are ignored). This is controlled by `article_min_tokens` on the class instance. | ||
|
||
Note that this iterates over the **texts**; if you want vectors, just use | ||
the standard corpus interface instead of this function:: | ||
|
@@ -380,6 +377,7 @@ def get_texts(self): | |
yield (tokens, (pageid, title)) | ||
else: | ||
yield tokens | ||
|
||
except KeyboardInterrupt: | ||
logger.warn( | ||
"user terminated iteration over Wikipedia corpus after %i documents with %i positions " | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to skip this test (not silently pass)., what do you think @steremma?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that this test overrides the one defined in
TestTextCorpus
. If we just skip it the parent definition will be called and it will fail because we plain text is not legit XML (nor is it compressed). In that sense passing it silently practically ignores it. The same idea is followed in the tests:of
TestTextCorpus
for these 4 tests defined in the parent classCorpusTestCase
. So I think its better to keep it as it is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best variant - change class hierarchy and interfaces, we should'nt give "useless" methods from parent class (change from
TestWikiCorpus -> TestTextCorpus
toTestTextCorpus -> BaseTestTextCorpus <- TestWikiCorpus
), but right now this isn't really needed, stay current variant with "pass".