Skip to content
jorisvanzundert edited this page Apr 16, 2016 · 1 revision

TypeError: add_witness()

I get a "TypeError: add_witness() takes 2 positional arguments but 3 were given" when trying:
collation.add_witness("A", "The quick brown fox jumps over the dog")

Note that there are two methods to feed in witnesses:

Collation.add_plain_witness( sigil, content )

and

Collation.add_witness( { 'id': sigil, 'content': content } )

The first form takes a sigil (e.g. "A") and a string (e.g. "Plain brown fox.") as arguments. This is your plain vanilla plain text parsing option. The second form enables you to feed in tokenized and/or annotated witnesses as dictionaries/hashes (which you may chose to read in from, for instance, JSON files). For a detailed description of the JSON format for this see: http://collatex.net/doc/#json-input

Example

      from collatex import *

      # Using a dictionary to pass in individual plain text witnesses
      collation = Collation()
      collation.add_witness( {
          "id" : "A",
          "content" : "The quick brown fox jumped over the lazy dogs." 
        } )
      collation.add_witness( {
          "id" : "B",
          "content" : "The quick fox jumped over the red dogs."
        } )
      alignment_table = collate(collation)
      print(alignment_table)

      # Using token hashes (e.g. parsed from a JSON file)
      collation = Collation()
      collation.add_witness( {
        "id" : "A",
        "tokens" : [ 
            { "t" : "The", "some_annotation" : 123 },
            { "t" : "quick" , "label_adj" : True },
            { "t" : "brown", "my_id" : "xyz" },
            { "t" : "fox", "another_annotation" : 123 },
            { "t" : "jumped" , "label_verb" : True },
            { "t" : "over", "my_id" : "xzy" },
            { "t" : "the", "annotation" : 123 },
            { "t" : "lazy" , "label_adj" : "true" },
            { "t" : "dogs.", "my_id" : "zyx" }
          ]
        } )
      collation.add_witness( {
        "id" : "B",
        "tokens" : [
            { "t" : "the", "n" : "The" },
            { "t" : "qick" , "n" : "quick", "label_adj" : "true" },
            { "t" : "browned", "n" : "brown", "my_id" : "xyz" },
            { "t" : "fox", "another_annotation" : 123 },
            { "t" : "beat" , "label_verb" : "true" },
            { "t" : "the", "annotation" : "123" },
            { "t" : "lazy" , "label_adj" : True },
            { "t" : "dogs.", "my_id" : "zyx" }
          ]
        } )
      alignment_table = collate(collation)
      print(alignment_table)
Clone this wiki locally