Skip to content

jianlins/PyFastNER

Repository files navigation

PyFastNER

PyFastNER is the python implementation of FastNER, which is orginally developed using Java. It uses hash function to process multiple rules at the same time. Similar to FastNER, PyFastNER supports token-based rules (FastNER--under developing) and character-based rules (FastCNER). It is licensed under the Apache License, Version 2.0.

Install:

pip install PyFastNER

Examples:

Here is a simiple example of using external dictionary to find matches in an input string. It will return a dictionary of spans grouped by the named entity types.

from PyFastNER import FastCNER
# initiate fastner using external rule file
fastner = FastCNER('conf/crule_test.tsv')
# process an input string
res = fastner.processString('Pt came with fever, T 102.0F.')
# display processed results
for type in res.keys():
	for span in res[type]:
		print(span)

Here is another example if you need process a sentence within a document, where you just need to tell the offset of the sentence to the beginning of the document.

from PyFastNER import FastCNER
fastner = FastCNER('conf/crule_test.tsv')
res = fastner.processString('Pt came with fever, T 102.0F.',134)

For more examples, please refer to TestFastCNER.py