lang-model/naive-nlu/tree_nlu/atoms.py
kenkeiras 79034f85a9 Move to a chaining model for tokenization.
This model also explores more tokenization possibilities.
With this, the tokenization tests are passed.
2018-04-15 20:06:23 +02:00

24 lines
474 B
Python

'''
Analogous to erlang ones.
"An atom is a literal, a constant with name."
'''
from collections import namedtuple
Atom = namedtuple('Atom', field_names='name')
def is_atom(element, name=None):
'''Check if an element is an atom with a specific name.'''
if not isinstance(element, Atom):
return False
if name is None:
return True
return element.name == name
def a(name):
'''Build an atom with a given name.'''
return Atom(name)