나는 concordace가 반환 한 인스턴스 뒤의 텍스트를 찾고 싶습니다. 예를 들어, 'Searching Text' section에있는 예제를 보면 '괴물'이라는 단어의 일치어가 표시됩니다. 괴물 같은 사례가 나온 직후에 단어를 어떻게 얻을 수 있습니까?NLTK의 색인을 부르는 것 - 사용 된 단어의 앞뒤에 텍스트를 가져 오는 방법?
10
A
답변
18
import nltk
import nltk.book as book
text1 = book.text1
c = nltk.ConcordanceIndex(text1.tokens, key = lambda s: s.lower())
print([text1.tokens[offset+1] for offset in c.offsets('monstrous')])
는
['size', 'bulk', 'clubs', 'cannibal', 'and', 'fable', 'Pictures', 'pictures', 'stories', 'cabinet', 'size']
내가
concordance
방법을 정의하는 방법을 찾는하여이 발견 얻을 수 있습니다.
이 text1.concordance
가 /usr/lib/python2.7/dist-packages/nltk/text.py
에 정의되어 보여줍니다 해당 파일에서
In [107]: text1.concordance?
Type: instancemethod
Base Class: <type 'instancemethod'>
String Form: <bound method Text.concordance of <Text: Moby Dick by Herman Melville 1851>>
Namespace: Interactive
File: /usr/lib/python2.7/dist-packages/nltk/text.py
당신이 ConcordanceIndex
객체를 생성하는 방법을 보여줍니다
def concordance(self, word, width=79, lines=25):
...
self._concordance_index = ConcordanceIndex(self.tokens,
key=lambda s:s.lower())
...
self._concordance_index.print_concordance(word, width, lines)
를 찾을 수 있습니다.
그리고 같은 파일에 당신은 또한 찾을 수 있습니다 다음 IPython 인터프리터에서 어떤 실험으로
class ConcordanceIndex(object):
def __init__(self, tokens, key=lambda x:x):
...
def print_concordance(self, word, width=75, lines=25):
...
offsets = self.offsets(word)
...
right = ' '.join(self._tokens[i+1:i+context])
,이 self.offsets('monstrous')
단어 monstrous
찾을 수있는 번호 (오프셋)의 목록을 제공 보여줍니다. 실제 단어는 self._tokens[offset]
이며 text1.tokens[offset]
과 동일합니다.
따라서 monstrous
다음 단어는 text1.tokens[offset+1]
입니다.
관련 문제
- 1. 사이트 색인을 가져 오는 방법
- 2. 창에서 텍스트를 가져 오는 방법
- 3. MessageUI.framework에서 사용 된 이미지를 가져 오는 방법
- 4. 링크 된 단어의 링크를 HTMLAgilityPack과 함께 유지하면서 모든 텍스트를 가져 오는 방법이 있습니까?
- 5. Regex - 주어진 토큰을 포함하는 가장 짧은 텍스트를 가져 오는 것
- 6. 텍스트를 가져 오는 중입니까?
- 7. AppWidgetProvider에서 TextView 텍스트를 가져 오는 방법
- 8. NSTextField 대리자 알림 - 텍스트를 가져 오는 방법?
- 9. 단어의 스타일에 텍스트를 바인딩하십시오.
- 10. xcode를 사용하여 웹 사이트에서 텍스트를 가져 오는 것
- 11. LinearLayout - 텍스트를 아이콘 오른쪽에 가져 오는 방법?
- 12. 회전 된 div 요소에 멋지게 앉아서 텍스트를 가져 오는 방법
- 13. NLTK "generate"함수 : 반환 된 텍스트를 가져 오는 방법?
- 14. webview에서 선택한 텍스트를 가져 오는 방법은 무엇입니까?
- 15. BindingResult에서 컨트롤러의 오류 텍스트를 가져 오는 방법
- 16. 텍스트를 html로 가져 오는 최상의 방법
- 17. ID-h에서 텍스트를 가져 오는 방법
- 18. android webview에서 선택한 텍스트를 가져 오는 방법
- 19. Android - 사용자가 텍스트를 가져 오는 방법?
- 20. AutoIt을 사용하여 ListBox에서 텍스트를 가져 오는 방법
- 21. 토스트 (Toast) 객체에서 텍스트를 가져 오는 방법
- 22. richboxtext silverlight에서 텍스트를 가져 오는 방법
- 23. PHP에서 배열로 파일에서 텍스트를 가져 오는 방법
- 24. jQuery : 페이지에서 텍스트를 가져 오는 방법?
- 25. 스팬 ID에서 텍스트를 가져 오는 방법
- 26. 색인을 사용하여 항목을 가져 오는 중,
- 27. JSON 요청에서 텍스트를 가져 오는 방법을
- 28. Python : NLTK의 형용사 Synsets
- 29. div로 텍스트를 가져 오는 중
- 30. iTextSharp - 페이지에서 단어의 위치를 얻는 방법