Generate a sentence, randomly or from a list of keywords/initials. This is based on Brown corpus.
Project description
# Random Sentence
Generate a sentence, randomly or from a list of keywords/initials. This is based on Brown corpus.
## Installation
Download the git, and cd, then run ` python setup.py install python -m nltk.downloader all `
## Usage
`pycon >>> from randomsentence import Brown >>> tagged_sentence = Brown().get_tagged_sent() >>> tagged_sentence [('She', 'PPS'), ('saw', 'VBD'), ('it', 'PPO'), ('then', 'RB'), (',', ','), ('the', 'AT'), ('distant', 'JJ'), ('derrick', 'NN'), ('of', 'IN'), ('the', 'AT'), ('wildcat', 'NN'), ('--', '--'), ('a', 'AT'), ('test', 'NN'), ('well', 'RB'), ('in', 'IN'), ('unexplored', 'JJ'), ('country', 'NN'), ('.', '.')] `
For Brown corpus, it is tagged based on Part-of-speech. This can easily be turned to a real sentence.
`pycon >>> from randomsentence import SentenceTool >>> sentence_tool = SentenceTool() >>> sentence_tool.detokenize_tagged(tagged_sentence) 'She saw it then, the distant derrick of the wildcat -- a test well in unexplored country.' >>> from randomsentence import KeywordParse >>> parser = KeywordParse() >>> tagged_sentence = parser.from_keyword_list(['love', 'blind', 'trouble']) >>> tagged_sentence [('On', False), ('the', False), ('love', True), ('he', False), ('stopped', False), ('at', False), ('the', False), ('blind', True), ('to', False), ('receive', False), ('his', False), ('trouble', True)] `
For KeywordParse, the word is tagged based on whether the keyword overlaps.
`pycon >>> sentence_tool.detokenize_tagged(tagged_sentence) 'On the love he stopped at the blind to receive his trouble' >>> tagged_sentence = parser.from_initials('JKr') >>> tagged_sentence [('These', False), ('joints', True), ('may', False), ('be', False), ('knotted', True), ('as', False), ('receives', True)] >>> sentence_tool.detokenize_tagged(tagged_sentence) 'These joints may be knotted as receives' `
Grammar fixing module is also included, in case minor grammar fix is needed. This is based on language-check / languagetool.
`pycon >>> from randomsentence import GrammarCorrector >>> corrector = GrammarCorrector() >>> corrector.correct('A sentence with a error in the Hitchhiker’s Guide tot he Galaxy') 'A sentence with an error in the Hitchhiker’s Guide to the Galaxy' `
## Todo
KeywordParse sometimes fail. It returns None on failure. This needs to be minimized.
## Found In
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for randomsentence-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b6f18d23fda8f1b3ab77c0375e30f17d261f441b1afdef3b92ad960d4083bdc |
|
MD5 | e9c36f700acbd515fc5bb8d78ecdfa3b |
|
BLAKE2b-256 | d682107cb0ce8a42de05be5212ec6d0a038a26da4facb59ad1719e7337695a8b |