파이썬에서 쉽게 임의의 단어와 문장을 생성합니다
github 저장소 | pypi | 선적 서류 비치
Wonderwords는 임의의 단어와 구조화 된 임의 문장을 생성하는 데 유용한 파이썬 패키지입니다. 또한 임의의 단어를 신속하게 생성하기위한 다채로운 명령 줄 인터페이스가 제공됩니다. 최신 버전은 GitHub에서 제공되며 안정 버전은 PYPI에서 사용할 수 있습니다.
Wonderwords가 할 수있는 것은 다음과 같습니다.
최신 버전의 WonderWords를 설치하려면 Python 패키지 인덱스에서 좋아하는 패키지 관리자를 사용하여 wonderwords 패키지를 설치하십시오. 예를 들어 PIP :
pip install wonderwordsPIP 사용으로 WonderWords를 업그레이드하려면 :
pip install --upgrade wonderwords설치가 작동했는지 확인하려면 Python에서 Wonderwords를 가져 오십시오.
import wonderwords ModuleNotFound 오류가 발생하면 위 단계에서 Wonderwords를 설치했는지 확인하십시오. 추가 문제를 보려면 Github 페이지에서 새로운 문제를 엽니 다.
이 섹션에서는 Wonderwords 사용법을 간단히 설명합니다. Wonderwords에는 명령 줄 인터페이스와 Python 모듈이 있으므로 두 개의 하위 섹션이 있습니다.
기본 임의의 단어 생성 클래스는 RandomWord 클래스입니다. word 메소드로 단어를 생성 할 수 있습니다.
from wonderwords import RandomWord
r = RandomWord ()
# generate a random word
r . word ()
# random word that starts with a and ends with en
r . word ( starts_with = "a" , ends_with = "en" )
# generate a random noun or adjective, by default all parts of speech are included
r . word ( include_parts_of_speech = [ "nouns" , "adjectives" ])
# generate a random word between the length of 3 and 8 characters
r . word ( word_min_length = 3 , word_max_length = 8 )
# generate a random word with a custom Python regular expression
r . word ( regex = ".*a" )
# some of the words in the default word lists have spaces, such as 'contact lens'
# this option disables them
r . word ( exclude_with_spaces = True )
# you can combine multiple filtering options
r . word ( starts_with = "ru" , word_max_length = 10 , include_parts_of_speech = [ "verbs" ]) filter 메소드를 사용하여 일부 기준과 일치하는 모든 단어 목록을 얻을 수도 있습니다.
# get a list of ALL words that start with "am"
r . filter ( starts_with = "am" )
# you can use all the options found in the word method:
r . filter ( ends_with = "k" , include_parts_of_speech = [ "verbs" ], word_min_length = 4 ) random_words 메소드를 사용하여 임의의 단어 목록을 생성 할 수도 있습니다. 이것은 반환 할 단어의 양을 지정하고 단어를 무작위로 선택하는 것을 제외하고는 필터 방법과 매우 유사합니다. 금액을 충족시키기에 충분한 단어가 없다면, NoWordsToChooseFrom 예외가 제기됩니다.
# get a list of 3 random nouns
r . random_words ( 3 , include_parts_of_speech = [ "nouns" ])
# you can use all the options found in the word method
r . random_words ( 5 , starts_with = "o" , word_min_length = 10 )
# if the amount of words you want to get is larger than the amount of words
# there are, a NoWordsToChooseFrom exception is raised:
r . random_words ( 100 , starts_with = "n" , word_min_length = 16 )
# there are less than 100 words that are at least 16 letters long and start with
# n, so an exception is raised
# you can silence the NoWordsToChooseFrom exception and return all words even
# if there are less, by setting return_less_if_necessary to True
r . random_words ( 100 , starts_with = "n" , word_min_length = 16 , return_less_if_necessary = True ) RandomSentence 클래스를 사용하여 임의의 문장을 쉽게 생성합니다.
from wonderwords import RandomSentence
s = RandomSentence ()
# Get a random bare-bone sentence
s . bare_bone_sentence ()
# Get a random bare-bone sentence with a direct object
s . simple_sentence ()
# Get a random bare-bone sentence with an adjective
s . bare_bone_with_adjective ()
# Get a random sentence with a subject, predicate, direct object and adjective
s . sentence () 단어는 "명사", "동사"및 "형용사"와 같은 범주로 구성됩니다. 자신만의 단어의 단어가 있다면 어떨까요? RandomWord 클래스를 인스턴스화 할 때 사용자 정의 범주를 지정할 수 있습니다.
from wonderwords import RandomWord
cars = [ "Chevrolet" , "Subaru" , "Tesla" ]
airplanes = [ "Boeing" , "Airbus" , "Cessna" ]
w = RandomWord ( cars = cars , airplanes = airplanes )
# Will return a random car or airplane
w . word ()
# Will return a random car
w . word ( include_categories = [ "cars" ])
# You can also mix and match custom categories with defaults
from wonderwords import Defaults
proper_nouns = [ "Austin" , "Seattle" , "New York" ]
w2 = RandomWord ( proper_nouns = proper_nouns , common_nouns = Defaults . NOUNS )
# Will return either Seattle or seat
w . word ( regex = "[Ss]eat.*" )마지막으로, 버전 2.3부터 Wonderwords는 단어 목록에서 욕설을 필터링하는 것을 명시 적으로 지원합니다. 현재 이것은 기초입니다.
from wonderwords import is_profanity , filter_profanity
# Test against words that could possibly be offensive. Good of user-facing apps.
is_profanity ( "apple" ) # False
# Can be done with a list
words = [ ... ]
# The function returns a generator, so we convert it to a list
words_clean = list ( filter_profanity ( words ))더 고급 사용량 (및 튜토리얼!)은 문서의 단어 추가 단어 추가와 같은 문서에 있습니다. 모든 정보가 포함 된 전체 문서는 https://wonderwords.readthedocs.io에서 찾을 수 있습니다.
참고 : 명령 줄 인터페이스 (CLI)를 사용하기 전에 pip install wonderwords[cli] 사용하여 CLI에 필요한 모든 종속성을 설치했는지 확인하십시오. Wonderwords는 일반적으로 종속성이 필요하지 않지만 명령 줄에서 색상화 된 출력에 풍부한 사용을 사용합니다.
Wonderwords는 명령 줄 인터페이스를 제공하며 wonderwords 명령과 함께 사용할 수 있습니다. 용법:
usage: wonderwords [-h] [-w] [-f] [-l LIST] [-s {bb,ss,bba,s}] [-v] [-S STARTS_WITH] [-e ENDS_WITH]
[-p {noun,verb,adjective,nouns,verbs,adjectives} [{noun,verb,adjective,nouns,verbs,adjectives} ...]]
[-m WORD_MIN_LENGTH] [-M WORD_MAX_LENGTH] [-r REGEX] [-x] [-d DELIMITER] [-E]
Generate random words and sentences from the command line. Here is a full list of available commands. To learn more
about each command, go to the documentation at https://wonderwords.readthedocs.io
options:
-h, --help show this help message and exit
-w, --word, --random-word
generate a random word
-f, --filter get a list of all known words matching the criteria specified
-l LIST, --list LIST return a list of a certain length of random words
-s {bb,ss,bba,s}, --sentence {bb,ss,bba,s}
return a sentence based on the structure chosen
-v, --version print the version number and exit
-S STARTS_WITH, --starts-with STARTS_WITH
strings the random word(s) should start with
-e ENDS_WITH, --ends-with ENDS_WITH
strings the random word(s) should end with
-p {noun,verb,adjective,nouns,verbs,adjectives} [{noun,verb,adjective,nouns,verbs,adjectives} ...], --parts-of-speech {noun,verb,adjective,nouns,verbs,adjectives} [{noun,verb,adjective,nouns,verbs,adjectives} ...]
only include certain parts of speech (by default all parts of speech are included)
-m WORD_MIN_LENGTH, --word-min-length WORD_MIN_LENGTH
minimum length of the word(s)
-M WORD_MAX_LENGTH, --word-max-length WORD_MAX_LENGTH
maximum length of the word(s)
-r REGEX, --regex REGEX, --re REGEX, --regular-expression REGEX
a python-style regular expression for the word(s) to match
-x, --exclude-with-spaces
exclude open compounds, such as 'contact lens'
-d DELIMITER, --delimiter DELIMITER
specify the delimiter to put between a list of words, default is ', '
-E, --suppress-error-on-less
suppress errors when less words are returned in a list then wanted
기본 명령은 다음과 같습니다.
-w : 임의의 단어를 생성합니다-f : filter 기능과 매우 유사하게 작동하여 특정 기준과 일치하는 모든 단어를 반환합니다.-l LIST : LIST 의 단어 목록 얻기-s {bb,ss,bba,s} : 임의의 문장 생성 :bb : 뼈 문장ss : 간단한 문장 (직접 대상을 가진 뼈 문장)bba : 형용사와 함께 뼈 문장s : 형용사로 간단한 문장을 생성하십시오 초기 단계에서 Wonderwords에는 설정된 버전 작성 시스템이 없었으므로 v2.0.0-alpha 이전의 버전은 혼란에 빠졌습니다. 버전 2 알파로 시작하여 Wonderwords는 반 버전화를 사용합니다.
Wonderwords는 오픈 소스이며 MIT 라이센스에 따라 배포됩니다. 자세한 내용은 라이센스를 참조하십시오.
모든 기부금은 환영하며 Wonderwords가 계속 증가하기를 바랍니다. 기고 가이드 라인과 시작 방법에 대해서는 CONTRIBUTING.md 읽음으로써 시작하십시오.
Wonderwords는 다음 작업 덕분에 가능했습니다.
profanitylist.txt