Skip to content

Extract_examples

Nagyfi Richárd edited this page Jan 10, 2018 · 3 revisions

The Extract class allows simple text processing. You can read more about it in the documentation.

from lara import parser

tweet	= '@sedthh ajánlj egy #nlp könyvtárat, amit 2017 februárjától kezdtek el írni ;)))9 https://github.com/sedthh/lara-hungarian-nlp'
info	= parser.Extract(tweet)
print(tweet)
print('Hashtags:',			info.hashtags())
print('Mentions:',			info.mentions())
print('Smileys:',			info.smileys())
print('URLs:',				info.urls())
print('Hun. date formats:',		info.dates())

>>> Hashtags: ['#nlp']
>>> Mentions: ['@sedthh']
>>> Smileys: [';)))9']
>>> URLs: ['https://github.com/sedthh/lara-hungarian-nlp']
>>> Hun. date formats: ['2017 februárjától']

It can also be used to detect commands sent to a Chatbot:

from lara import parser

user_text		= '/echo visszhang teszt' # /echo command
info			= parser.Extract(user_text)
commands		= info.commands()
func			= commands[0]
args			= commands[1]	# list
	
if func:
	if func == 'ping':
		print('pong') # nem íródik ki
	elif func == 'echo':
		print(' '.join(args)) # az args valójában egy lista
else:
	print('Parancs nélküli üzenet') # nem íródik ki

>>> visszhang teszt
Clone this wiki locally