-
Notifications
You must be signed in to change notification settings - Fork 6
fix chunking issue #3
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
Open
npow
wants to merge
2
commits into
ryan-lowe:master
Choose a base branch
from
npow:fix_chunks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| *.pyc | ||
|
|
||
| # Windows image file caches | ||
| Thumbs.db | ||
| ehthumbs.db | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import itertools | ||
| import nltk | ||
| import os | ||
| import re | ||
| from twokenize import tokenize | ||
|
|
||
| def is_number(s): | ||
| try: | ||
| float(s) | ||
| return True | ||
| except ValueError: | ||
| return False | ||
|
|
||
| def is_url(s): | ||
| return s.startswith('http://') or s.startswith('https://') or s.startswith('ftp://') \ | ||
| or s.startswith('ftps://') or s.startswith('smb://') | ||
|
|
||
| def clean_str(string, TREC=False): | ||
| """ | ||
| Tokenization/string cleaning for all datasets except for SST. | ||
| Every dataset is lower cased except for TREC | ||
| """ | ||
| string = re.sub(r"\'m", " \'m", string) | ||
| string = re.sub(r"\'s", " \'s", string) | ||
| string = re.sub(r"\'ve", " \'ve", string) | ||
| string = re.sub(r"n\'t", " n\'t", string) | ||
| string = re.sub(r"\'re", " \'re", string) | ||
| string = re.sub(r"\'d", " \'d", string) | ||
| string = re.sub(r"\'ll", " \'ll", string) | ||
| string = re.sub(r"`", " ` ", string) | ||
| string = re.sub(r",", " , ", string) | ||
| return string.strip() | ||
|
|
||
| def process_token(c): | ||
| """ | ||
| Use NLTK to replace named entities with generic tags. | ||
| Also replace URLs, numbers, and paths. | ||
| """ | ||
| nodelist = ['PERSON', 'ORGANIZATION', 'GPE', 'LOCATION', 'FACILITY', 'GSP'] | ||
| if hasattr(c, 'label'): | ||
| if c.label() in nodelist: | ||
| return "__%s__" % c.label() | ||
| word = c[0] | ||
| if is_url(word): | ||
| return "__URL__" | ||
| elif is_number(word): | ||
| return "__NUMBER__" | ||
| elif os.path.isabs(word): | ||
| return "__PATH__" | ||
| return word | ||
|
|
||
| def process_line(s, clean_string=True): | ||
| """ | ||
| Processes a line by iteratively calling process_token. | ||
| """ | ||
| if clean_string: | ||
| s = clean_str(s) | ||
| tokens = tokenize(s) | ||
| sent = nltk.pos_tag(tokens) | ||
| chunks = nltk.ne_chunk(sent, binary=False) | ||
| return [process_token(c).lower().encode('UTF-8') for c in chunks] | ||
|
|
||
| def test(): | ||
| s=''' | ||
| hi, please some1 can help me with my driver in ubuntu :( its a intel GM965 i tried compiz, but give me the error, Checking for Xgl: not present. Blacklisted PCIID '8086:2a02' found aborting and using fallback: /usr/bin/metacity some1 can help me please :( what kind of video card are you running? if you're not sure exactly, lspci | grep -i vga will tell you nickrud 00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (rev 03) http://wiki.compiz-fusion.org/Hardware/Blacklist nickrud ty i go try it | ||
| ''' | ||
|
|
||
| print process_line(s) | ||
|
|
||
| if __name__ == '__main__': | ||
| test() | ||
|
|
||
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.
You can use c.leaves() to flatten the words in a tree. Maybe its better?
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.
If it's a tree and it has a
labelproperty, we can simply return the label. I've added a check in cea46ad to handle the case if the tree doesn't have a label.