Exemplo n.º 1
0
def chunkstring(name='', string=''):
    """
    Create a chunk when given a string. The string is specified in the form: slot value slot value (arbitrary number of slot-value pairs can be used). isa-slot is used as the type of chunk. If no isa-slot is provided, chunk is assigned an 'undefined' type.

    For example:
    >>> chunkstring(name="example0", string='isa chunktype_example0 value one')
    chunktype_example0(value= one)
    """
    chunk_reader = utilities.getchunk()
    chunk = chunk_reader.parseString(string, parseAll=True)
    type_chunk, chunk_dict = createchunkdict(chunk)
    created_chunk = makechunk(name, type_chunk, **chunk_dict)
    return created_chunk
Exemplo n.º 2
0
def chunkstring(name='', string=''):
    """
    Create a chunk when given a string. The string is specified in the form: slot value slot value (arbitrary number of slot-value pairs can be used). isa-slot is used as the type of chunk. If no isa-slot is provided, chunk is assigned an 'undefined' type.

    For example:
    >>> chunkstring(name="example0", string='isa chunktype_example0 value one')
    chunktype_example0(value= one)
    """
    chunk_reader = utilities.getchunk()
    chunk = chunk_reader.parseString(string, parseAll=True)
    try:
        type_chunk, chunk_dict = createchunkdict(chunk)
    except utilities.ACTRError as e:
        raise utilities.ACTRError("The chunk string %s is not defined correctly; %s" %(string, e))

    created_chunk = makechunk(name, type_chunk, **chunk_dict)
    return created_chunk