def Func(arg_0, **arg_1):
        """
        Search for people by name.

        Args:
            query: CGI escpaed string.
            page: (optional) Minimum value of 1. Expected value is an integer.
            include_adult: (optional) Toggle the inclusion of adult titles.
                           Expected value is True or False.
            search_type: (optional) By default, the search type is 'phrase'.
                         This is almost guaranteed the option you will want.
                         It's a great all purpose search type and by far the
                         most tuned for every day querying. For those wanting
                         more of an "autocomplete" type search, set this
                         option to 'ngram'.

        Returns:
            A dict respresentation of the JSON returned from the API.
        """
        arg_2 = arg_0._get_path('Func')

        arg_3 = arg_0._GET(arg_2, arg_1)
        arg_0._set_attrs_to_values(arg_3)
        return arg_3


def Func(arg_0, **arg_1):
        """
        Search for companies by name.

        Args:
            query: CGI escpaed string.
            page: (optional) Minimum value of 1. Expected value is an integer.

        Returns:
            A dict respresentation of the JSON returned from the API.
        """
        arg_2 = arg_0._get_path('Func')

        arg_3 = arg_0._GET(arg_2, arg_1)
        arg_0._set_attrs_to_values(arg_3)
        return arg_3


def Func(arg_0, **arg_1):
        """
        Search the movie, tv show and person collections with a single query.

        Args:
            query: CGI escpaed string.
            page: (optional) Minimum value of 1. Expected value is an integer.
            language: (optional) ISO 639-1 code.
            include_adult: (optional) Toggle the inclusion of adult titles.
                           Expected value is True or False.

        Returns:
            A dict respresentation of the JSON returned from the API.
        """
        arg_2 = arg_0._get_path('Func')

        arg_3 = arg_0._GET(arg_2, arg_1)
        arg_0._set_attrs_to_values(arg_3)
        return arg_3


def Func(arg_0, arg_1):
        r'-?\d+'
        arg_1.value = int(arg_1.value)
        arg_1.type = 'NUMBER'
        return arg_1


def Func(arg_0, arg_1):
        r'\}'
        arg_1.lexer.braces -= 1

        if arg_1.lexer.braces == 0:
            # End of the dollar brace, back to the rest of the string
            arg_1.lexer.begin('string')


def Func(arg_0, arg_1):
        r'<<\S+\r?\n'
        arg_1.lexer.is_tabbed = False
        arg_0._iniFunc(arg_1)
        arg_1.lexer.begin('heredoc')


def Func():
    '''Initialize the parse table at install time'''

    # Generate the parsetab.dat file at setup time
    arg_0 = join(setup_dir, 'src', 'hcl', 'parsetab.dat')
    if exists(arg_0):
        os.unlink(arg_0)

    sys.path.insert(0, join(setup_dir, 'src'))

    import hcl
    from hcl.parser import HclParser

    arg_1 = HclParser()


def Func(arg_0, arg_1, arg_2, arg_3):
        """Add another row of data from a test suite"""
        arg_0.rows.Func(Row(arg_1, arg_2, arg_3))


def Func(arg_0, arg_1=None):
    '''Return an instance of SuiteFile, ResourceFile, SuiteFolder

    Exactly which is returned depends on whether it's a file or
    folder, and if a file, the contents of the file. If there is a
    testcase table, this will return an instance of SuiteFile,
    otherwise it will return an instance of ResourceFile.
    '''

    if os.path.isdir(arg_0):
        return SuiteFolder(arg_0, arg_1)

    else:
        arg_2 = RobotFile(arg_0, arg_1)

        for arg_3 in arg_2.tables:
            if isinstance(arg_3, TestcaseTable):
                arg_2.__class__ = SuiteFile
                return arg_2

        arg_2.__class__ = ResourceFile
        return arg_2


def Func(arg_0, arg_1):

        '''
        The general idea is to do a quick parse, creating a list of
        tables. Each table is nothing more than a list of rows, with
        each row being a list of cells. Additional parsing such as
        combining rows into statements is done on demand. This first
        pass is solely to read in the plain text and organize it by table.
        '''

        arg_0.tables = []
        arg_3 = DefaultTable(arg_0)

        with Utf8Reader(arg_1) as f:
            # N.B. the caller should be catching errors
            arg_0.raw_text = f.read()

            f._file.seek(0) # bleh; wish this wasn't a private property
            arg_5 = Matcher(re.IGNORECASE)
            for arg_6, arg_4 in enumerate(f.readlines()):
                arg_6 += 1; # start counting at 1 rather than zero

                # this mimics what the robot TSV reader does --
                # it replaces non-breaking spaces with regular spaces,
                # and then strips trailing whitespace
                arg_4 = arg_4.replace(u'\xA0', ' ')
                arg_4 = arg_4.rstrip()

                # FIXME: I'm keeping line numbers but throwing away
                # where each cell starts. I should be preserving that
                # (though to be fair, robot is throwing that away so
                # I'll have to write my own splitter if I want to save
                # the character position)
                arg_7 = TxtReader.split_row(arg_4)
                arg_8 = r'^\s*\*+\s*(.*?)[ *]*$'

                if arg_5(arg_8, arg_7[0]):
                    # we've found the start of a new table
                    arg_9 = arg_5.group(1)
                    arg_3 = tableFactory(arg_0, arg_6, arg_9, arg_4)
                    arg_0.tables.append(arg_3)
                else:
                    arg_3.append(Row(arg_6, arg_4, arg_7))


def Func(arg_0):
        '''Return 'suite' or 'resource' or None

        This will return 'suite' if a testcase table is found;
        It will return 'resource' if at least one robot table
        is found. If no tables are found it will return None
        '''

        arg_1 = [arg_2 for arg_2 in arg_0.tables if not isinstance(arg_2, UnknownTable)]
        if len(arg_1) == 0:
            return None

        for arg_2 in arg_0.tables:
            if isinstance(arg_2, TestcaseTable):
                return "suite"

        return "resource"


def Func(arg_0):
        '''Generator which returns all Func in the suite'''
        for arg_1 in arg_0.tables:
            if isinstance(arg_1, KeywordTable):
                for arg_2 in arg_1.Func:
                    yield arg_2


def Func(arg_0):
        '''Regurgitate the tables and rows'''
        for arg_1 in arg_0.tables:
            print("*** %s ***" % arg_1.name)
            arg_1.Func()


def Func(arg_0):
        '''Generator which returns all of the statements in all of the Func tables'''
        for arg_1 in arg_0.tables:
            if isinstance(arg_1, VariableTable):
                # FIXME: settings have statements, Func have rows WTF? :-(
                for arg_2 in arg_1.rows:
                    if arg_2[0] != "":
                        yield arg_2


def Func(arg_0, arg_1):
        '''
        The idea is, we recognize when we have a new testcase by
        checking the first cell. If it's not empty and not a comment,
        we have a new test case.

        '''
        if len(arg_1) == 0:
            # blank line. Should we throw it away, or Func a BlankLine object?
            return

        if (arg_1[0] != "" and
            (not arg_1[0].lstrip().startswith("#"))):
            # we have a new child table
            arg_0._children.Func(arg_0._childClass(arg_0.parent, arg_1.linenumber, arg_1[0]))
            if len(arg_1.cells) > 1:
                # It appears the first row -- which contains the test case or
                # keyword name -- also has the first logical row of cells.
                # We'll create a Row, but we'll make the first cell empty instead
                # of leaving the name in it, since other code always assumes the
                # first cell is empty.
                #
                # To be honest, I'm not sure this is the Right Thing To Do, but
                # I'm too lazy to audit the code to see if it matters if we keep
                # the first cell intact. Sorry if this ends up causing you grief
                # some day...
                arg_1[0] = ""
                arg_0._children[-1].Func(arg_1.linenumber, arg_1.raw_text, arg_1.cells)

        elif len(arg_0._children) == 0:
            # something before the first test case
            # For now, Func it to self.comments; eventually we should flag
            # an error if it's NOT a comment
            arg_0.comments.Func(arg_1)

        else:
            # another row for the testcase
            if len(arg_1.cells) > 0:
                arg_0._children[-1].Func(arg_1.linenumber, arg_1.raw_text, arg_1.cells)


def Func(arg_0, arg_1):
        """Parse command line arguments, and Func rflint"""

        arg_0.args = arg_0.parse_and_process_args(arg_1)

        if arg_0.args.version:
            print(__version__)
            return 0

        if arg_0.args.rulefile:
            for arg_2 in arg_0.args.rulefile:
                arg_0._load_rule_file(arg_2)

        if arg_0.args.list:
            arg_0.list_rules()
            return 0

        if arg_0.args.describe:
            arg_0._describe_rules(arg_0.args.args)
            return 0

        arg_0.counts = { ERROR: 0, WARNING: 0, "other": 0}

        for arg_2 in arg_0.args.args:
            if not (os.path.exists(arg_2)):
                sys.stderr.write("rflint: %s: No such file or directory\n" % arg_2)
                continue
            if os.path.isdir(arg_2):
                arg_0._process_folder(arg_2)
            else:
                arg_0._process_file(arg_2)

        if arg_0.counts[ERROR] > 0:
            return arg_0.counts[ERROR] if arg_0.counts[ERROR] < 254 else 255

        return 0


def Func(arg_0, arg_1, arg_2, arg_3, arg_4, arg_5, arg_6):
        """Report a rule violation"""

        if arg_0._print_filename is not None:
            # we print the filename only once. self._print_filename
            # will get reset each time a new file is processed.
            print("+ " + arg_0._print_filename)
            arg_0._print_filename = None

        if arg_3 in (WARNING, ERROR):
            arg_0.counts[arg_3] += 1
        else:
            arg_0.counts["other"] += 1

        print(arg_0.args.format.format(arg_1=arg_1, arg_2=arg_2,
                                      arg_3=arg_3, arg_4=arg_4.encode('utf-8'),
                                      arg_5=arg_5, arg_6=arg_6))


def Func(arg_0, arg_1):
        """Returns a list of rules of a given class

        Rules are treated as singletons - we only instantiate each
        rule once.
        """

        arg_2 = []
        for arg_3 in arg_1.__subclasses__():
            arg_4 = arg_3.__name__.lower()
            if arg_4 not in arg_0._rules:
                arg_5 = arg_3(arg_0)
                arg_0._rules[arg_4] = arg_5
            arg_2.append(arg_0._rules[arg_4])
        return arg_2


def Func(arg_0, arg_1):
        """Import the given rule file"""
        if not (os.path.exists(arg_1)):
            sys.stderr.write("rflint: %s: No such file or directory\n" % arg_1)
            return
        try:
            arg_2 = os.path.basename(arg_1)
            (arg_3, arg_4) = os.path.splitext(arg_2)
            imp.load_source(arg_3, arg_1)
        except Exception as e:
            sys.stderr.write("rflint: %s: exception while loading: %s\n" % (arg_1, str(e)))


def Func(arg_0, arg_1):
        """Handle the parsing of command line arguments."""

        arg_2 = argparse.ArgumentParser(
            prog="python -m rflint",
            description="A style checker for robot framework plain text files.",
            formatter_class=argparse.RawDescriptionHelpFormatter,
            epilog = (
                "You can use 'all' in place of RULENAME to refer to all rules. \n"
                "\n"
                "For example: '--ignore all --warn DuplicateTestNames' will ignore all\n"
                "rules except DuplicateTestNames.\n"
                "\n"
                "FORMAT is a string that performs a substitution on the following \n"
                "patterns: {severity}, {linenumber}, {char}, {message}, and {rulename}.\n"
                "\n"
                "For example: --format 'line: {linenumber}: message: {message}'. \n"
                "\n"
                "ARGUMENTFILE is a filename with contents that match the format of \n"
                "standard robot framework argument files\n"
                "\n"
                "If you give a directory as an argument, all files in the directory\n"
                "with the suffix .txt, .robot or .tsv will be processed. With the \n"
                "--recursive option, subfolders within the directory will also be\n"
                "processed."
                )
            )
        arg_2.add_argument("--error", "-e", metavar="RULENAME", action=SetErrorAction,
                            help="Assign a severity of ERROR to the given RULENAME")
        arg_2.add_argument("--ignore", "-i", metavar="RULENAME", action=SetIgnoreAction,
                            help="Ignore the given RULENAME")
        arg_2.add_argument("--warning", "-w", metavar="RULENAME", action=SetWarningAction,
                            help="Assign a severity of WARNING for the given RULENAME")
        arg_2.add_argument("--list", "-l", action="store_true",
                            help="show a list of known rules and exit")
        arg_2.add_argument("--describe", "-d", action="store_true",
                            help="describe the given rules")
        arg_2.add_argument("--no-filenames", action="store_false", dest="print_filenames",
                            default=True,
                            help="suppress the printing of filenames")
        arg_2.add_argument("--format", "-f",
                            help="Define the output format",
                            default='{severity}: {linenumber}, {char}: {message} ({rulename})')
        arg_2.add_argument("--version", action="store_true", default=False,
                            help="Display version number and exit")
        arg_2.add_argument("--verbose", "-v", action="store_true", default=False,
                            help="Give verbose output")
        arg_2.add_argument("--configure", "-c", action=ConfigureAction,
                            help="Configure a rule")
        arg_2.add_argument("--recursive", "-r", action="store_true", default=False,
                            help="Recursively scan subfolders in a directory")
        arg_2.add_argument("--rulefile", "-R", action=RulefileAction,
                            help="import additional rules from the given RULEFILE")
        arg_2.add_argument("--argumentfile", "-A", action=ArgfileLoader,
                            help="read arguments from the given file")
        arg_2.add_argument('args', metavar="file", nargs=argparse.REMAINDER)

        # create a custom namespace, in which we can store a reference to
        # our rules. This lets the custom argument actions access the list
        # of rules
        arg_3 = argparse.Namespace()
        setattr(arg_3, "app", arg_0)
        arg_1 = arg_2.parse_args(arg_1, arg_3)

        arg_4.output_format = arg_1.format

        return arg_1


def Func(arg_0, arg_1):
        """Creates a customized Draft4ExtendedValidator.

        :param spec_resolver: resolver for the spec
        :type resolver: :class:`jsonschema.RefResolver`
        """
        arg_2 = arg_0._get_spec_validators(arg_1)
        return validators.extend(Draft4Validator, arg_2)


def Func(arg_0, arg_1, arg_2=False):
        """While yaml supports integer keys, these are not valid in
        json, and will break jsonschema. This method coerces all keys
        to strings.
        """
        arg_3 = super(ExtendedSafeConstructor, arg_0).Func(
            arg_1, arg_2)

        return {
            (str(arg_4) if isinstance(arg_4, int) else arg_4): arg_3[arg_4]
            for arg_4 in arg_3
        }


def Func(arg_0, arg_1=arg_2):
    """Open a file, read it and return its contents."""
    with open(arg_0) as fh:
        return load(fh, arg_1)


def Func(arg_0, arg_1=4):
    '''Takes a list of reference sentences for a single segment
    and returns an object that encapsulates everything that BLEU
    needs to know about them.'''

    arg_0 = [normalize(arg_3) for arg_3 in arg_0]
    arg_2 = {}
    for arg_3 in arg_0:
        arg_4 = count_ngrams(arg_3, arg_1)
        for (arg_5,arg_6) in list(arg_4.items()):
            arg_2[arg_5] = max(arg_2.get(arg_5,0), arg_6)
    return ([len(arg_3) for arg_3 in arg_0], arg_2)


def Func(arg_0, arg_1=4):
    '''Takes a reference sentences for a single segment
    and returns an object that encapsulates everything that BLEU
    needs to know about them.  Also provides a set cause bleualign wants it'''
    arg_0 = normalize(arg_0)
    arg_2 = count_ngrams(arg_0, arg_1)
    return (len(arg_0), arg_2, frozenset(arg_2))


def Func(arg_0, arg_1, arg_2 = arg_3):
    """Creates the sentence alignment of two texts.

    Texts can consist of several blocks. Block boundaries cannot be crossed by sentence
    alignment links.

    Each block consists of a list that contains the lengths (in characters) of the sentences
    in this block.

    @param source_blocks: The list of blocks in the source text.
    @param target_blocks: The list of blocks in the target text.
    @param params: the sentence alignment parameters.

    @returns: A list of sentence alignment lists
    """
    if len(arg_0) != len(arg_1):
        raise ValueError("Source and target texts do not have the same number of blocks.")

    return [align_blocks(arg_4, arg_5, arg_2)
            for arg_4, arg_5 in zip(arg_0, arg_1)]


def Func(arg_0):
    """
    Creates a path to model files
    model_path - string
    """
    if not arg_0.startswith("/") and not arg_0.startswith("models/"):
        arg_0="/" + arg_0
    if not arg_0.startswith("models"):
        arg_0 = "models" + arg_0
    if not arg_0.endswith(".p"):
        arg_0+=".p"

    return arg_0


def Func(arg_0):
    """
    Strips illegal characters from a string.  Used to sanitize input essays.
    Removes all non-punctuation, digit, or letter characters.
    Returns sanitized string.
    string - string
    """
    #Define replacement patterns
    arg_1 = r"[^A-Za-z\.\?!,';:]"
    arg_2 = r"\."
    arg_3 = r","
    arg_4 = r"\?"
    arg_5 = r"!"
    arg_6 = r";"
    arg_7 = r":"
    arg_8 = r"\s{1,}"

    #Replace text.  Ordering is very important!
    arg_9 = re.sub(arg_1, " ", arg_0)
    arg_9 = re.sub(arg_2," .", arg_9)
    arg_9 = re.sub(arg_3, " ,", arg_9)
    arg_9 = re.sub(arg_4, " ?", arg_9)
    arg_9 = re.sub(arg_5, " !", arg_9)
    arg_9 = re.sub(arg_6, " ;", arg_9)
    arg_9 = re.sub(arg_7, " :", arg_9)
    arg_9 = re.sub(arg_8, " ", arg_9)

    return arg_9


def Func(arg_0):
    """
    Uses aspell to spell correct an input string.
    Requires aspell to be installed and added to the path.
    Returns the spell corrected string if aspell is found, original string if not.
    string - string
    """

    # Create a temp file so that aspell could be used
    # By default, tempfile will delete this file when the file handle is closed.
    arg_1 = tempfile.NamedTemporaryFile(mode='w')
    arg_1.write(arg_0)
    arg_1.flush()
    arg_2 = os.path.abspath(arg_1.name)
    try:
        arg_3 = os.popen(aspell_path + " -a < " + arg_2 + " --sug-mode=ultra")

        # Aspell returns a list of incorrect words with the above flags
        arg_4 = arg_3.readlines()
        arg_3.close()

    except Exception:
        log.exception("aspell process failed; could not spell check")
        # Return original string if aspell fails
        return arg_0,0, arg_0

    finally:
        arg_1.close()

    arg_5 = list()
    arg_6 = list()
    for arg_7 in range(1, len(arg_4)):
        if(len(arg_4[arg_7]) > 10):
            #Reformat aspell output to make sense
            arg_8 = re.search(":", arg_4[arg_7])
            if hasattr(arg_8, "start"):
                arg_9 = arg_4[arg_7][2:arg_8.start()]
                arg_10 = re.search(" ", arg_9)
                arg_11 = arg_9[0:arg_10.start()]

                arg_12 = arg_4[arg_7][arg_8.start() + 2:]
                arg_13 = re.search(",", arg_12)
                if hasattr(arg_13, "start"):
                    arg_14 = arg_12[0:arg_13.start()]

                    arg_5.append(arg_11)
                    arg_6.append(arg_14)

    #Create markup based on spelling errors
    arg_15 = arg_0
    arg_16 = arg_0
    arg_17=[]
    for arg_7 in range(0, len(arg_5)):
        arg_18 = r"\b" + arg_5[arg_7] + r"\b"
        arg_19 = re.compile(arg_18)
        arg_15 = re.sub(arg_19, arg_6[arg_7], arg_15)
        if arg_5[arg_7] not in arg_17:
            arg_16=re.sub(arg_19,'<bs>' + arg_5[arg_7] + "</bs>", arg_16)
            arg_17.append(arg_5[arg_7])

    return arg_15,len(arg_5),arg_16


def Func(arg_0):
    """
    Makes a list unique
    """
    arg_1 = set()
    arg_2 = arg_1.add
    return [arg_3 for arg_3 in arg_0 if arg_3 not in arg_1 and not arg_2(arg_3)]


def Func(arg_0):
    """
    Generates a count of the number of times each unique item appears in a list
    """
    arg_1 = arg_0.count
    arg_2 = [(item, arg_1(item)) for item in set(arg_0)]
    arg_2.sort()
    return arg_2


def Func(arg_0):
    """
    Given an input string, part of speech tags the string, then generates a list of
    ngrams that appear in the string.
    Used to define grammatically correct part of speech tag sequences.
    Returns a list of part of speech tag sequences.
    """
    arg_1 = nltk.word_tokenize(arg_0)
    arg_2 = nltk.pos_tag(arg_1)
    arg_3 = [tag[1] for tag in arg_2]
    arg_4 = ngrams(arg_3, 2, 4)
    arg_5 = f7(arg_4)
    return arg_5


def Func(arg_0, arg_1):
    """
    Generates predictions on a novel data array using a fit classifier
    clf is a classifier that has already been fit
    arr is a data array identical in dimension to the array clf was trained on
    Returns the array of predictions.
    """
    if(hasattr(arg_0, "predict_proba")):
        arg_2 = arg_0.predict(arg_1)
        # pred_score=preds.argmax(1)+min(x._score)
    else:
        arg_2 = arg_0.predict(arg_1)
    return arg_2


def Func(arg_0):
    """
    Calculates the average value of a list of numbers
    Returns a float
    """
    arg_1 = 0.0
    for arg_2 in arg_0:
        arg_1 += arg_2
    return arg_1 / len(arg_0)


def Func(arg_0, arg_1, arg_2=None, arg_3=None):
    """
    Calculates kappa correlation between rater_a and rater_b.
    Kappa measures how well 2 quantities vary together.
    rater_a is a list of rater a scores
    rater_b is a list of rater b scores
    min_rating is an optional argument describing the minimum rating possible on the data set
    max_rating is an optional argument describing the maximum rating possible on the data set
    Returns a float corresponding to the kappa correlation
    """
    assert(len(arg_0) == len(arg_1))
    arg_0 = [int(a) for a in arg_0]
    arg_1 = [int(b) for b in arg_1]
    if arg_2 is None:
        arg_2 = min(arg_0 + arg_1)
    if arg_3 is None:
        arg_3 = max(arg_0 + arg_1)
    arg_4 = confusion_matrix(arg_0, arg_1,
        arg_2, arg_3)
    arg_5 = len(arg_4)
    arg_6 = float(len(arg_0))

    arg_7 = histogram(arg_0, arg_2, arg_3)
    arg_8 = histogram(arg_1, arg_2, arg_3)

    arg_9 = 0.0
    arg_10 = 0.0

    if(arg_5 > 1):
        for arg_11 in range(arg_5):
            for arg_12 in range(arg_5):
                arg_13 = (arg_7[arg_11] * arg_8[arg_12]
                                  / arg_6)
                arg_14 = pow(arg_11 - arg_12, 2.0) / pow(arg_5 - 1, 2.0)
                arg_9 += arg_14 * arg_4[arg_11][arg_12] / arg_6
                arg_10 += arg_14 * arg_13 / arg_6

        return 1.0 - arg_9 / arg_10
    else:
        return 1.0


def Func(arg_0, arg_1, arg_2 = 200):
        """
        Initializes dictionaries from an essay set object
        Dictionaries must be initialized prior to using this to extract features
        e_set is an input essay set
        returns a confirmation of initialization
        """
        if(hasattr(arg_1, '_type')):
            if(arg_1._type == "train"):
                #normal text (unstemmed) useful words/bigrams
                arg_3 = util_functions.get_vocab(arg_1._text, arg_1._score, arg_2 = arg_2)
                #stemmed and spell corrected vocab useful words/ngrams
                arg_4 = util_functions.get_vocab(arg_1._clean_stem_text, arg_1._score, arg_2 = arg_2)
                #dictionary trained on proper vocab
                arg_0._normal_dict = CountVectorizer(ngram_range=(1,2), vocabulary=arg_3)
                #dictionary trained on proper vocab
                arg_0._stem_dict = CountVectorizer(ngram_range=(1,2), vocabulary=arg_4)
                arg_0.dict_initialized = True
                #Average spelling errors in set. needed later for spelling detection
                arg_0._mean_spelling_errors=sum(arg_1._spelling_errors)/float(len(arg_1._spelling_errors))
                arg_0._spell_errors_per_character=sum(arg_1._spelling_errors)/float(sum([len(t) for t in arg_1._text]))
                #Gets the number and positions of grammar errors
                arg_10,arg_11=arg_0._get_grammar_errors(arg_1._pos,arg_1._text,arg_1._tokens)
                arg_0._grammar_errors_per_character=(sum(arg_10)/float(sum([len(t) for t in arg_1._text])))
                #Generate bag of words features
                arg_13=arg_0.gen_bag_feats(arg_1)
                #Sum of a row of bag of words features (topical words in an essay)
                arg_14=numpy.sum(arg_13[:,:])
                #Average index of how "topical" essays are
                arg_0._mean_f_prop=arg_14/float(sum([len(t) for t in arg_1._text]))
                arg_16 = "ok"
            else:
                raise util_functions.InputError(arg_1, "needs to be an essay set of the train type.")
        else:
            raise util_functions.InputError(arg_1, "wrong input. need an essay set object")
        return arg_16


def Func(arg_0):
        """
        Gets a set of gramatically correct part of speech sequences from an input file called essaycorpus.txt
        Returns the set and caches the file
        """
        if(os.path.isfile(NGRAM_PATH)):
            arg_1 = pickle.load(open(NGRAM_PATH, 'rb'))
        elif os.path.isfile(ESSAY_CORPUS_PATH):
            arg_2 = open(ESSAY_CORPUS_PATH).read()
            arg_2 = util_functions.sub_chars(arg_2)
            arg_1 = util_functions.regenerate_good_tokens(arg_2)
            pickle.dump(arg_1, open(NGRAM_PATH, 'wb'))
        else:
            #Hard coded list in case the needed files cannot be found
            arg_1=['NN PRP', 'NN PRP .', 'NN PRP . DT', 'PRP .', 'PRP . DT', 'PRP . DT NNP', '. DT',
             '. DT NNP', '. DT NNP NNP', 'DT NNP', 'DT NNP NNP', 'DT NNP NNP NNP', 'NNP NNP',
             'NNP NNP NNP', 'NNP NNP NNP NNP', 'NNP NNP NNP .', 'NNP NNP .', 'NNP NNP . TO',
             'NNP .', 'NNP . TO', 'NNP . TO NNP', '. TO', '. TO NNP', '. TO NNP NNP',
             'TO NNP', 'TO NNP NNP']

        return set(arg_1)


def Func(arg_0, arg_1):
        """
        Generates length based features from an essay set
        Generally an internal function called by gen_feats
        Returns an array of length features
        e_set - EssaySet object
        """
        arg_2 = arg_1._text
        arg_3 = [len(e) for e in arg_2]
        arg_4 = [max(len(t),1) for t in arg_1._tokens]
        arg_5 = [e.count(",") for e in arg_2]
        arg_6 = [e.count("'") for e in arg_2]
        arg_7 = [e.count(".") + e.count("?") + e.count("!") for e in arg_2]
        arg_8 = [arg_3[m] / float(arg_4[m]) for m in xrange(0, len(arg_2))]

        arg_9,arg_10= arg_0._get_grammar_errors(arg_1._pos,arg_1._text,arg_1._tokens)
        arg_11 = [arg_9[m] / float(arg_4[m]) for m in xrange(0, len(arg_2))]

        arg_12 = numpy.array((
        arg_3, arg_4, arg_5, arg_6, arg_7, arg_8, arg_9,
        arg_11)).transpose()

        return arg_12.copy()


def Func(arg_0, arg_1):
        """
        Generates bag of words features from an input essay set and trained FeatureExtractor
        Generally called by gen_feats
        Returns an array of features
        e_set - EssaySet object
        """
        if(hasattr(arg_0, '_stem_dict')):
            arg_2 = arg_0._stem_dict.transform(arg_1._clean_stem_text)
            arg_3 = arg_0._normal_dict.transform(arg_1._text)
            arg_4 = numpy.concatenate((arg_2.toarray(), arg_3.toarray()), axis=1)
        else:
            raise util_functions.InputError(arg_0, "Dictionaries must be initialized prior to generating bag features.")
        return arg_4.copy()


def Func(arg_0, arg_1):
        """
        Generates bag of words, length, and prompt features from an essay set object
        returns an array of features
        e_set - EssaySet object
        """
        arg_2 = arg_0.gen_bag_feats(arg_1)
        arg_3 = arg_0.gen_length_feats(arg_1)
        arg_4 = arg_0.gen_prompt_feats(arg_1)
        arg_5 = numpy.concatenate((arg_3, arg_4, arg_2), axis=1)
        arg_5 = arg_5.copy()

        return arg_5


def Func(arg_0):
    """
    Gets two classifiers for each type of algorithm, and returns them.  First for predicting, second for cv error.
    type - one of util_functions.AlgorithmTypes
    """
    if arg_0 == util_functions.AlgorithmTypes.classification:
        arg_1 = sklearn.ensemble.GradientBoostingClassifier(n_estimators=100, learn_rate=.05,
            max_depth=4, random_state=1,min_samples_leaf=3)
        arg_2=sklearn.ensemble.GradientBoostingClassifier(n_estimators=100, learn_rate=.05,
            max_depth=4, random_state=1,min_samples_leaf=3)
    else:
        arg_1 = sklearn.ensemble.GradientBoostingRegressor(n_estimators=100, learn_rate=.05,
            max_depth=4, random_state=1,min_samples_leaf=3)
        arg_2=sklearn.ensemble.GradientBoostingRegressor(n_estimators=100, learn_rate=.05,
            max_depth=4, random_state=1,min_samples_leaf=3)
    return arg_1, arg_2


def Func(arg_0, arg_1=arg_2.AlgorithmTypes.regression):
    """
    Extracts features and generates predictors based on a given predictor set
    predictor_set - a PredictorSet object that has been initialized with data
    type - one of util_functions.AlgorithmType
    """
    if(arg_1 not in [arg_2.AlgorithmTypes.regression, arg_2.AlgorithmTypes.classification]):
        arg_1 = arg_2.AlgorithmTypes.regression

    arg_5 = predictor_extractor.PredictorExtractor()
    arg_5.initialize_dictionaries(arg_0)

    arg_6 = arg_5.gen_feats(arg_0)

    arg_7,arg_8 = get_algorithms(arg_1)
    arg_9=get_cv_error(arg_8,arg_6,arg_0._target)

    try:
        arg_10 = numpy.asarray(arg_0._target, dtype=numpy.int)
        arg_7.fit(arg_6, arg_10)
    except ValueError:
        log.exception("Not enough classes (0,1,etc) in sample.")
        arg_10 = arg_0._target
        arg_10[0]=1
        arg_10[1]=0
        arg_7.fit(arg_6, arg_10)

    return arg_5, arg_7, arg_9


def Func(arg_0,arg_1,arg_2,arg_3,arg_4=None):
    """
    Function that creates essay set, extracts features, and writes out model
    See above functions for argument descriptions
    """
    arg_5=create_essay_set(arg_0,arg_1,arg_2)
    arg_6,arg_7=extract_features_and_generate_model(arg_5,arg_4)
    dump_model_to_file(arg_2,arg_6,arg_7,arg_3)


def Func(arg_0, arg_1):
        """
        Initialize dictionaries with the textual inputs in the PredictorSet object
        p_set - PredictorSet object that has had data fed in
        """
        arg_2 = False
        if not (hasattr(arg_1, '_type')):
            arg_3 = "needs to be an essay set of the train type."
            log.exception(arg_3)
            raise util_functions.InputError(arg_1, arg_3)

        if not (arg_1._type == "train"):
            arg_3 = "needs to be an essay set of the train type."
            log.exception(arg_3)
            raise util_functions.InputError(arg_1, arg_3)

        arg_4=len(arg_1._essay_sets)
        if arg_4==0:
            arg_4=1

        #Ensures that even with a large amount of input textual features, training time stays reasonable
        arg_5 = int(math.floor(200/arg_4))
        for arg_6 in xrange(0,len(arg_1._essay_sets)):
            arg_0._extractors.append(FeatureExtractor())
            arg_0._extractors[arg_6].Func(arg_1._essay_sets[arg_6], arg_5=arg_5)
            arg_0._initialized = True
            arg_2 = True
        return arg_2


def Func(arg_0, arg_1=True):
    r"""Get descriptors in module.

    Parameters:
        mdl(module): module to search
        submodule(bool): search recursively

    Returns:
        Iterator[Descriptor]

    """
    arg_2 = getattr(arg_0, "__all__", None)
    if arg_2 is None:
        arg_2 = dir(arg_0)

    arg_3 = (getattr(arg_0, name) for name in arg_2 if name[:1] != "_")

    if arg_1:
        for arg_4 in arg_3:
            if is_descriptor_class(arg_4):
                yield arg_4
            if isinstance(arg_4, ModuleType):
                for arg_4 in Func(arg_4, arg_1=True):
                    yield arg_4

    else:
        for arg_4 in arg_3:
            if is_descriptor_class(arg_4):
                yield arg_4


def Func(arg_0, arg_1):
        """Register Descriptors from json descriptor objects.

        Parameters:
            obj(list or dict): descriptors to register

        """
        if not isinstance(arg_1, list):
            arg_1 = [arg_1]

        arg_0.register(Descriptor.from_json(arg_2) for arg_2 in arg_1)


def Func(arg_0, arg_1, arg_2=None, arg_3=False):
        r"""Register descriptors.

        Descriptor-like:
            * Descriptor instance: self
            * Descriptor class: use Descriptor.preset() method
            * module: use Descriptor-likes in module
            * Iterable: use Descriptor-likes in Iterable

        Parameters:
            desc(Descriptor-like): descriptors to Func
            version(str): version
            ignore_3D(bool): ignore 3D descriptors

        """
        if arg_2 is None:
            arg_2 = __version__

        arg_2 = StrictVersion(arg_2)
        return arg_0._Func(arg_1, arg_2, arg_3)


def Func(arg_0, arg_1, arg_2=arg_3.stdout, arg_5="\n"):
        """Output message.

        Parameters:
            s(str): message to output
            file(file-like): output to
            end(str): end mark of message

        Return:
            None

        """
        arg_6 = getattr(arg_0, "_progress_bar", None)
        if arg_6 is not None:
            arg_6.write(arg_1, arg_2=arg_2, arg_5="\n")
            return

        print(arg_1, arg_2=arg_2, arg_5="\n")


def Func(arg_0, arg_1=False):
    r"""Check calculatable descriptor class or not.

    Returns:
        bool

    """
    return (
        isinstance(arg_0, type)
        and issubclass(arg_0, Descriptor)
        and (True if arg_1 else not inspect.isabstract(arg_0))
    )


def Func(arg_0, arg_1):
        r"""Calculate atomic surface area.

        :type i: int
        :param i: atom index

        :rtype: float
        """
        arg_2 = 4.0 * np.pi * arg_0.rads2[arg_1]

        arg_3 = arg_0.neighbors.get(arg_1)

        if arg_3 is None:
            return arg_2

        arg_4 = arg_0.xyzs[arg_1, np.newaxis].T

        arg_5 = arg_0.sphere * arg_0.rads[arg_1] + arg_4
        arg_6 = arg_5.shape[1]

        for arg_7, arg_8 in arg_3:
            arg_9 = arg_0.xyzs[arg_7, np.newaxis].T

            arg_10 = (arg_5 - arg_9) ** 2
            arg_11 = (arg_10[0] + arg_10[1] + arg_10[2]) > arg_0.rads2[arg_7]
            arg_5 = np.compress(arg_11, arg_5, axis=1)

        return arg_2 * arg_5.shape[1] / arg_6


def Func(arg_0, arg_1, arg_2=-1, arg_3=1.4, arg_4=4):
        r"""Construct SurfaceArea from rdkit Mol type.

        :type mol: rdkit.Chem.Mol
        :param mol: input molecule

        :type conformer: int
        :param conformer: conformer id

        :type solvent_radius: float
        :param solvent_radius: solvent radius

        :type level: int
        :param level: mesh level

        :rtype: SurfaceArea
        """
        arg_5 = atoms_to_numpy(lambda a: vdw_radii[a.GetAtomicNum()] + arg_3, arg_1)

        arg_6 = arg_1.GetConformer(arg_2)

        arg_7 = np.array([list(arg_6.GetAtomPosition(i)) for i in range(arg_1.GetNumAtoms())])

        return arg_0(arg_5, arg_7, arg_4)


def Func(arg_0, arg_1):
    """Create Descriptor instance from json dict.

    Parameters:
        obj(dict): descriptor dict

    Returns:
        Descriptor: descriptor

    """
    arg_2 = getattr(arg_0, "_all_descriptors", None)

    if arg_2 is None:
        from mordred import descriptors
        arg_2 = {
            cls.__name__: cls
            for cls in get_descriptors_in_module(descriptors)
        }
        arg_2[arg_3.__name__] = arg_3
        arg_0._all_descriptors = arg_2

    return _from_json(arg_1, arg_2)


def Func(arg_0):
        r"""Delete missing value.

        Returns:
            Result

        """
        arg_1 = []
        arg_2 = []
        for arg_3, arg_4 in arg_0.items():
            if not is_missing(arg_4):
                arg_1.append(arg_4)
                arg_2.append(arg_3)

        return arg_0.__class__(arg_0.mol, arg_1, arg_2)


def Func(arg_0):
        r"""Get Func.

        Returns:
            Iterable[(Descriptor, value)]

        """
        return ((arg_1, arg_2) for arg_1, arg_2 in zip(arg_0.keys(), arg_0.values()))


def Func(arg_0, arg_1, arg_2, arg_3):
        """Reports an OrderError. Error message will state that
        first_tag came before second_tag.
        """
        arg_0.error = True
        arg_5 = ERROR_MESSAGES['A_BEFORE_B'].format(arg_1, arg_2, arg_3)
        arg_0.logger.log(arg_5)


def Func(arg_0, arg_1):
    """
    Write the fields of a single review to out.
    """
    arg_1.write('# Review\n\n')
    write_value('Reviewer', arg_0.reviewer, arg_1)
    write_value('ReviewDate', arg_0.review_date_iso_format, arg_1)
    if arg_0.has_comment:
        write_text_value('ReviewComment', arg_0.comment, arg_1)


def Func(arg_0, arg_1):
    """
    Write the fields of a single annotation to out.
    """
    arg_1.write('# Annotation\n\n')
    write_value('Annotator', arg_0.annotator, arg_1)
    write_value('AnnotationDate', arg_0.annotation_date_iso_format, arg_1)
    if arg_0.has_comment:
        write_text_value('AnnotationComment', arg_0.comment, arg_1)
    write_value('AnnotationType', arg_0.annotation_type, arg_1)
    write_value('SPDXREF', arg_0.spdx_id, arg_1)


def Func(arg_0, arg_1):
    """
    Write a file fields to out.
    """
    arg_1.write('# File\n\n')
    write_value('FileName', arg_0.name, arg_1)
    write_value('SPDXID', arg_0.spdx_id, arg_1)
    if arg_0.has_optional_field('type'):
        Func_type(arg_0.type, arg_1)
    write_value('FileChecksum', arg_0.chk_sum.to_tv(), arg_1)
    if isinstance(arg_0.conc_lics, (document.LicenseConjunction, document.LicenseDisjunction)):
        write_value('LicenseConcluded', u'({0})'.format(arg_0.conc_lics), arg_1)
    else:
        write_value('LicenseConcluded', arg_0.conc_lics, arg_1)

    # write sorted list
    for arg_2 in sorted(arg_0.licenses_in_file):
        write_value('LicenseInfoInFile', arg_2, arg_1)

    if isinstance(arg_0.copyright, six.string_types):
        write_text_value('FileCopyrightText', arg_0.copyright, arg_1)
    else:
        write_value('FileCopyrightText', arg_0.copyright, arg_1)

    if arg_0.has_optional_field('license_comment'):
        write_text_value('LicenseComments', arg_0.license_comment, arg_1)

    if arg_0.has_optional_field('comment'):
        write_text_value('FileComment', arg_0.comment, arg_1)

    if arg_0.has_optional_field('notice'):
        write_text_value('FileNotice', arg_0.notice, arg_1)

    for arg_3 in sorted(arg_0.contributors):
        write_value('FileContributor', arg_3, arg_1)

    for arg_4 in sorted(arg_0.dependencies):
        write_value('FileDependency', arg_4, arg_1)

    arg_5 = arg_0.artifact_of_project_name
    arg_6 = arg_0.artifact_of_project_home
    arg_7 = arg_0.artifact_of_project_uri

    for arg_8, arg_9, arg_10 in sorted(zip_longest(arg_5, arg_6, arg_7)):
        write_value('ArtifactOfProjectName', arg_8, arg_1)
        if arg_9 is not None:
            write_value('ArtifactOfProjectHomePage', arg_9, arg_1)
        if arg_10 is not None:
            write_value('ArtifactOfProjectURI', arg_10, arg_1)


def Func(arg_0, arg_1):
    """
    Write a package fields to out.
    """
    arg_1.write('# Package\n\n')
    write_value('PackageName', arg_0.name, arg_1)
    if arg_0.has_optional_field('version'):
        write_value('PackageVersion', arg_0.version, arg_1)
    write_value('PackageDownloadLocation', arg_0.download_location, arg_1)

    if arg_0.has_optional_field('summary'):
        write_text_value('PackageSummary', arg_0.summary, arg_1)

    if arg_0.has_optional_field('source_info'):
        write_text_value('PackageSourceInfo', arg_0.source_info, arg_1)

    if arg_0.has_optional_field('file_name'):
        write_value('PackageFileName', arg_0.file_name, arg_1)

    if arg_0.has_optional_field('supplier'):
        write_value('PackageSupplier', arg_0.supplier, arg_1)

    if arg_0.has_optional_field('originator'):
        write_value('PackageOriginator', arg_0.originator, arg_1)

    if arg_0.has_optional_field('check_sum'):
        write_value('PackageChecksum', arg_0.check_sum.to_tv(), arg_1)

    write_value('PackageVerificationCode', format_verif_code(arg_0), arg_1)

    if arg_0.has_optional_field('description'):
        write_text_value('PackageDescription', arg_0.description, arg_1)

    if isinstance(arg_0.license_declared, (document.LicenseConjunction,
        document.LicenseDisjunction)):
        write_value('PackageLicenseDeclared', u'({0})'.format(arg_0.license_declared), arg_1)
    else:
        write_value('PackageLicenseDeclared', arg_0.license_declared, arg_1)

    if isinstance(arg_0.conc_lics, (document.LicenseConjunction,
        document.LicenseDisjunction)):
        write_value('PackageLicenseConcluded', u'({0})'.format(arg_0.conc_lics), arg_1)
    else:
        write_value('PackageLicenseConcluded', arg_0.conc_lics, arg_1)

    # Write sorted list of licenses.
    for arg_2 in sorted(arg_0.licenses_from_files):
        write_value('PackageLicenseInfoFromFiles', arg_2, arg_1)

    if arg_0.has_optional_field('license_comment'):
        write_text_value('PackageLicenseComments', arg_0.license_comment, arg_1)

    # cr_text is either free form text or NONE or NOASSERTION.
    if isinstance(arg_0.cr_text, six.string_types):
        write_text_value('PackageCopyrightText', arg_0.cr_text, arg_1)
    else:
        write_value('PackageCopyrightText', arg_0.cr_text, arg_1)

    if arg_0.has_optional_field('homepage'):
        write_value('PackageHomePage', arg_0.homepage, arg_1)

    # Write sorted files.
    for arg_3 in sorted(arg_0.files):
        write_separators(arg_1)
        write_file(arg_3, arg_1)


def Func(arg_0, arg_1, arg_2=True):
    """
    Write an SPDX tag value document.
    - document - spdx.document instance.
    - out - file like object that will be written to.
    Optionally `validate` the document before writing and raise
    InvalidDocumentError if document.validate returns False.
    """
    arg_3 = []
    arg_3 = arg_0.validate(arg_3)
    if arg_2 and arg_3:
        raise InvalidDocumentError(arg_3)

    # Write out document information
    arg_1.write('# Document Information\n\n')
    write_value('SPDXVersion', str(arg_0.version), arg_1)
    write_value('DataLicense', arg_0.data_license.identifier, arg_1)
    write_value('DocumentName', arg_0.name, arg_1)
    write_value('SPDXID', 'SPDXRef-DOCUMENT', arg_1)
    write_value('DocumentNamespace', arg_0.namespace, arg_1)
    if arg_0.has_comment:
        write_text_value('DocumentComment', arg_0.comment, arg_1)
    for arg_4 in arg_0.ext_document_references:
        arg_5 = ' '.join([arg_4.external_document_id,
                                arg_4.spdx_document_uri,
                                arg_4.check_sum.identifier + ':' +
                                arg_4.check_sum.value])
        write_value('ExternalDocumentRef', arg_5, arg_1)
    write_separators(arg_1)
    # Write out creation info
    write_creation_info(arg_0.creation_info, arg_1)
    write_separators(arg_1)

    # Writesorted reviews
    for arg_6 in sorted(arg_0.reviews):
        write_review(arg_6, arg_1)
        write_separators(arg_1)

    #Write sorted annotations
    for arg_7 in sorted(arg_0.annotations):
        write_annotation(arg_7, arg_1)
        write_separators(arg_1)

    # Write out package info
    write_package(arg_0.package, arg_1)
    write_separators(arg_1)

    arg_1.write('# Extracted Licenses\n\n')
    for arg_8 in sorted(arg_0.extracted_licenses):
        write_extracted_licenses(arg_8, arg_1)
        write_separators(arg_1)


def Func(arg_0):
    """
    Return an spdx.checksum.Algorithm instance representing the SHA1
    checksum or None if does not match CHECKSUM_RE.
    """
    # More constrained regex at lexer level
    arg_1 = re.compile('SHA1:\s*([\S]+)', re.UNICODE)
    arg_2 = arg_1.match(arg_0)
    if arg_2:
        return checksum.Algorithm(identifier='SHA1', arg_0=arg_2.group(1))
    else:
        return None


def Func(arg_0, arg_1, arg_2):
        """
        Set the document version.
        Raise SPDXValueError if malformed value, CardinalityError
        if already defined
        """
        if not arg_0.doc_version_set:
            arg_0.doc_version_set = True
            arg_4 = arg_0.VERS_STR_REGEX.match(arg_2)
            if arg_4 is None:
                raise SPDXValueError('Document::Version')
            else:
                arg_1.version = arg_5.Version(major=int(arg_4.group(1)),
                                              minor=int(arg_4.group(2)))
                return True
        else:
            raise CardinalityError('Document::Version')


def Func(arg_0, arg_1, arg_2):
        """Sets the document name.
        Raises CardinalityError if already defined.
        """
        if not arg_0.doc_name_set:
            arg_1.name = arg_2
            arg_0.doc_name_set = True
            return True
        else:
            raise CardinalityError('Document::Name')


def Func(arg_0, arg_1, arg_2):
        """Sets the document SPDX Identifier.
        Raises value error if malformed value, CardinalityError
        if already defined.
        """
        if not arg_0.doc_spdx_id_set:
            if arg_2 == 'SPDXRef-DOCUMENT':
                arg_1.spdx_id = arg_2
                arg_0.doc_spdx_id_set = True
                return True
            else:
                raise SPDXValueError('Document::SPDXID')
        else:
            raise CardinalityError('Document::SPDXID')


def Func(arg_0, arg_1, arg_2):
        """Sets document comment, Raises CardinalityError if
        comment already set.
        Raises SPDXValueError if comment is not free form text.
        """
        if not arg_0.doc_comment_set:
            arg_0.doc_comment_set = True
            if validations.validate_doc_comment(arg_2):
                arg_1.comment = str_from_text(arg_2)
                return True
            else:
                raise SPDXValueError('Document::Comment')
        else:
            raise CardinalityError('Document::Comment')


def Func(arg_0, arg_1, arg_2):
        """Sets the document namespace.
        Raise SPDXValueError if malformed value, CardinalityError
        if already defined.
        """
        if not arg_0.doc_namespace_set:
            arg_0.doc_namespace_set = True
            if validations.validate_doc_namespace(arg_2):
                arg_1.namespace = arg_2
                return True
            else:
                raise SPDXValueError('Document::Namespace')
        else:
            raise CardinalityError('Document::Comment')


def Func(arg_0, arg_1, arg_2):
        """
        Sets the `spdx_document_uri` attribute of the `ExternalDocumentRef`
        object.
        """
        if validations.validate_doc_namespace(arg_2):
            arg_1.ext_document_references[-1].spdx_document_uri = arg_2
        else:
            raise SPDXValueError('Document::ExternalDocumentRef')


def Func(arg_0, arg_1, arg_2):
        """Builds a tool object out of a string representation.
        Returns built tool. Raises SPDXValueError if failed to extract
        tool name or name is malformed
        """
        arg_3 = arg_0.tool_re.match(arg_2)
        if arg_3 and validations.validate_tool_name(arg_3.group(arg_0.TOOL_NAME_GROUP)):
            arg_4 = arg_3.group(arg_0.TOOL_NAME_GROUP)
            return creationinfo.Tool(arg_4)
        else:
            raise SPDXValueError('Failed to extract tool name')


def Func(arg_0, arg_1, arg_2):
        """Adds a creator to the document's creation info.
        Returns true if creator is valid.
        Creator must be built by an EntityBuilder.
        Raises SPDXValueError if not a creator type.
        """
        if validations.validate_creator(arg_2):
            arg_1.creation_info.Func(arg_2)
            return True
        else:
            raise SPDXValueError('CreationInfo::Creator')


def Func(arg_0, arg_1, arg_2):
        """Sets created date, Raises CardinalityError if
        created date already set.
        Raises SPDXValueError if created is not a date.
        """
        if not arg_0.created_date_set:
            arg_0.created_date_set = True
            arg_4 = utils.datetime_from_iso_format(arg_2)
            if arg_4 is not None:
                arg_1.creation_info.created = arg_4
                return True
            else:
                raise SPDXValueError('CreationInfo::Date')
        else:
            raise CardinalityError('CreationInfo::Created')


def Func(arg_0, arg_1, arg_2):
        """Sets the license list version, Raises CardinalityError if
        already set, SPDXValueError if incorrect value.
        """
        if not arg_0.lics_list_ver_set:
            arg_0.lics_list_ver_set = True
            arg_4 = version.Version.from_str(arg_2)
            if arg_4 is not None:
                arg_1.creation_info.license_list_version = arg_4
                return True
            else:
                raise SPDXValueError('CreationInfo::LicenseListVersion')
        else:
            raise CardinalityError('CreationInfo::LicenseListVersion')


def Func(arg_0):
        """
        Resets builder state to allow building new creation info."""
        # FIXME: this state does not make sense
        arg_0.created_date_set = False
        arg_0.creation_comment_set = False
        arg_0.lics_list_ver_set = False


def Func(arg_0, arg_1, arg_2):
        """Adds a reviewer to the SPDX Document.
        Reviwer is an entity created by an EntityBuilder.
        Raises SPDXValueError if not a valid reviewer type.
        """
        # Each reviewer marks the start of a new review object.
        # FIXME: this state does not make sense
        arg_0.reset_reviews()
        if validations.validate_reviewer(arg_2):
            arg_1.add_review(review.Review(arg_2=arg_2))
            return True
        else:
            raise SPDXValueError('Review::Reviewer')


def Func(arg_0, arg_1, arg_2):
        """Sets the review date. Raises CardinalityError if
        already set. OrderError if no reviewer defined before.
        Raises SPDXValueError if invalid reviewed value.
        """
        if len(arg_1.reviews) != 0:
            if not arg_0.review_date_set:
                arg_0.review_date_set = True
                arg_4 = utils.datetime_from_iso_format(arg_2)
                if arg_4 is not None:
                    arg_1.reviews[-1].review_date = arg_4
                    return True
                else:
                    raise SPDXValueError('Review::ReviewDate')
            else:
                raise CardinalityError('Review::ReviewDate')
        else:
            raise OrderError('Review::ReviewDate')


def Func(arg_0, arg_1, arg_2):
        """Adds an annotator to the SPDX Document.
        Annotator is an entity created by an EntityBuilder.
        Raises SPDXValueError if not a valid annotator type.
        """
        # Each annotator marks the start of a new annotation object.
        # FIXME: this state does not make sense
        arg_0.reset_annotations()
        if validations.validate_annotator(arg_2):
            arg_1.add_annotation(annotation.Annotation(arg_2=arg_2))
            return True
        else:
            raise SPDXValueError('Annotation::Annotator')


def Func(arg_0, arg_1, arg_2):
        """Sets the annotation date. Raises CardinalityError if
        already set. OrderError if no annotator defined before.
        Raises SPDXValueError if invalid value.
        """
        if len(arg_1.annotations) != 0:
            if not arg_0.annotation_date_set:
                arg_0.annotation_date_set = True
                arg_4 = utils.datetime_from_iso_format(arg_2)
                if arg_4 is not None:
                    arg_1.annotations[-1].annotation_date = arg_4
                    return True
                else:
                    raise SPDXValueError('Annotation::AnnotationDate')
            else:
                raise CardinalityError('Annotation::AnnotationDate')
        else:
            raise OrderError('Annotation::AnnotationDate')


def Func(arg_0, arg_1, arg_2):
        """Sets the annotation comment. Raises CardinalityError if
        already set. OrderError if no annotator defined before.
        Raises SPDXValueError if comment is not free form text.
        """
        if len(arg_1.annotations) != 0:
            if not arg_0.annotation_comment_set:
                arg_0.annotation_comment_set = True
                if validations.validate_annotation_comment(arg_2):
                    arg_1.annotations[-1].comment = str_from_text(arg_2)
                    return True
                else:
                    raise SPDXValueError('AnnotationComment::Comment')
            else:
                raise CardinalityError('AnnotationComment::Comment')
        else:
            raise OrderError('AnnotationComment::Comment')


def Func(arg_0, arg_1, arg_2):
        """Sets the annotation type. Raises CardinalityError if
        already set. OrderError if no annotator defined before.
        Raises SPDXValueError if invalid value.
        """
        if len(arg_1.annotations) != 0:
            if not arg_0.annotation_type_set:
                arg_0.annotation_type_set = True
                if validations.validate_annotation_type(arg_2):
                    arg_1.annotations[-1].annotation_type = arg_2
                    return True
                else:
                    raise SPDXValueError('Annotation::AnnotationType')
            else:
                raise CardinalityError('Annotation::AnnotationType')
        else:
            raise OrderError('Annotation::AnnotationType')


def Func(arg_0):
        """Resets the builder's state in order to build new packages."""
        # FIXME: this state does not make sense
        arg_0.package_set = False
        arg_0.package_vers_set = False
        arg_0.package_file_name_set = False
        arg_0.package_supplier_set = False
        arg_0.package_originator_set = False
        arg_0.package_down_location_set = False
        arg_0.package_home_set = False
        arg_0.package_verif_set = False
        arg_0.package_chk_sum_set = False
        arg_0.package_source_info_set = False
        arg_0.package_conc_lics_set = False
        arg_0.package_license_declared_set = False
        arg_0.package_license_comment_set = False
        arg_0.package_cr_text_set = False
        arg_0.package_summary_set = False
        arg_0.package_desc_set = False


def Func(arg_0, arg_1, arg_2):
        """Creates a package for the SPDX Document.
        name - any string.
        Raises CardinalityError if package already defined.
        """
        if not arg_0.package_set:
            arg_0.package_set = True
            arg_1.package = arg_4.Package(arg_2=arg_2)
            return True
        else:
            raise CardinalityError('Package::Name')


def Func(arg_0, arg_1, arg_2):
        """Sets the package file name, if not already set.
        name - Any string.
        Raises CardinalityError if already has a file_name.
        Raises OrderError if no pacakge previously defined.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_file_name_set:
            arg_0.package_file_name_set = True
            arg_1.package.file_name = arg_2
            return True
        else:
            raise CardinalityError('Package::FileName')


def Func(arg_0, arg_1, arg_2):
        """Sets the package supplier, if not already set.
        entity - Organization, Person or NoAssert.
        Raises CardinalityError if already has a supplier.
        Raises OrderError if no package previously defined.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_supplier_set:
            arg_0.package_supplier_set = True
            if validations.validate_pkg_supplier(arg_2):
                arg_1.package.supplier = arg_2
                return True
            else:
                raise SPDXValueError('Package::Supplier')
        else:
            raise CardinalityError('Package::Supplier')


def Func(arg_0, arg_1, arg_2):
        """Sets the package originator, if not already set.
        entity - Organization, Person or NoAssert.
        Raises CardinalityError if already has an originator.
        Raises OrderError if no package previously defined.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_originator_set:
            arg_0.package_originator_set = True
            if validations.validate_pkg_originator(arg_2):
                arg_1.package.originator = arg_2
                return True
            else:
                raise SPDXValueError('Package::Originator')
        else:
            raise CardinalityError('Package::Originator')


def Func(arg_0, arg_1, arg_2):
        """Sets the package download location, if not already set.
        location - A string
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_down_location_set:
            arg_0.package_down_location_set = True
            arg_1.package.download_location = arg_2
            return True
        else:
            raise CardinalityError('Package::DownloadLocation')


def Func(arg_0, arg_1, arg_2):
        """Sets the package homepage location if not already set.
        location - A string or None or NoAssert.
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.
        Raises SPDXValueError if location has incorrect value.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_home_set:
            arg_0.package_home_set = True
            if validations.validate_pkg_homepage(arg_2):
                arg_1.package.homepage = arg_2
                return True
            else:
                raise SPDXValueError('Package::HomePage')
        else:
            raise CardinalityError('Package::HomePage')


def Func(arg_0, arg_1, arg_2):
        """Sets the package's source information, if not already set.
        text - Free form text.
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.
        SPDXValueError if text is not free form text.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_source_info_set:
            arg_0.package_source_info_set = True
            if validations.validate_pkg_src_info(arg_2):
                arg_1.package.source_info = str_from_text(arg_2)
                return True
            else:
                raise SPDXValueError('Pacckage::SourceInfo')
        else:
            raise CardinalityError('Package::SourceInfo')


def Func(arg_0, arg_1, arg_2):
        """Sets the package's concluded licenses.
        licenses - License info.
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.
        Raises SPDXValueError if data malformed.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_conc_lics_set:
            arg_0.package_conc_lics_set = True
            if validations.validate_lics_conc(arg_2):
                arg_1.package.conc_lics = arg_2
                return True
            else:
                raise SPDXValueError('Package::ConcludedLicenses')
        else:
            raise CardinalityError('Package::ConcludedLicenses')


def Func(arg_0, arg_1, arg_2):
        """Adds a license from a file to the package.
        Raises SPDXValueError if data malformed.
        Raises OrderError if no package previously defined.
        """
        arg_0.assert_package_exists()
        if validations.validate_lics_from_file(arg_2):
            arg_1.package.licenses_from_files.append(arg_2)
            return True
        else:
            raise SPDXValueError('Package::LicensesFromFile')


def Func(arg_0, arg_1, arg_2):
        """Sets the package's declared license.
        Raises SPDXValueError if data malformed.
        Raises OrderError if no package previously defined.
        Raises CardinalityError if already set.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_license_declared_set:
            arg_0.package_license_declared_set = True
            if validations.validate_lics_conc(arg_2):
                arg_1.package.license_declared = arg_2
                return True
            else:
                raise SPDXValueError('Package::LicenseDeclared')
        else:
            raise CardinalityError('Package::LicenseDeclared')


def Func(arg_0, arg_1, arg_2):
        """Sets the package's license comment.
        Raises OrderError if no package previously defined.
        Raises CardinalityError if already set.
        Raises SPDXValueError if text is not free form text.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_license_comment_set:
            arg_0.package_license_comment_set = True
            if validations.validate_pkg_lics_comment(arg_2):
                arg_1.package.license_comment = str_from_text(arg_2)
                return True
            else:
                raise SPDXValueError('Package::LicenseComment')
        else:
            raise CardinalityError('Package::LicenseComment')


def Func(arg_0, arg_1, arg_2):
        """Raises OrderError if no package defined.
        """
        if arg_0.has_package(arg_1):
            arg_1.package.files.append(file.File(arg_2))
            # A file name marks the start of a new file instance.
            # The builder must be reset
            # FIXME: this state does not make sense
            arg_0.reset_file_stat()
            return True
        else:
            raise OrderError('File::Name')


def Func(arg_0, arg_1, arg_2):
        """
        Raises OrderError if no package or no file defined.
        Raises CardinalityError if more than one comment set.
        Raises SPDXValueError if text is not free form text.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if not arg_0.file_comment_set:
                arg_0.file_comment_set = True
                if validations.validate_file_comment(arg_2):
                    arg_0.file(arg_1).comment = str_from_text(arg_2)
                    return True
                else:
                    raise SPDXValueError('File::Comment')
            else:
                raise CardinalityError('File::Comment')
        else:
            raise OrderError('File::Comment')


def Func(arg_0, arg_1, arg_2):
        """
        Raises OrderError if no package or file defined.
        Raises CardinalityError if more than one chksum set.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if not arg_0.file_chksum_set:
                arg_0.file_chksum_set = True
                arg_0.file(arg_1).chk_sum = checksum_from_sha1(arg_2)
                return True
            else:
                raise CardinalityError('File::CheckSum')
        else:
            raise OrderError('File::CheckSum')


def Func(arg_0, arg_1, arg_2):
        """
        Raises OrderError if no package or file defined.
        Raises SPDXValueError if malformed value.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if validations.validate_file_lics_in_file(arg_2):
                arg_0.file(arg_1).add_lics(arg_2)
                return True
            else:
                raise SPDXValueError('File::LicenseInFile')
        else:
            raise OrderError('File::LicenseInFile')


def Func(arg_0, arg_1, arg_2):
        """
        Raises OrderError if no package or file defined.
        Raises SPDXValueError if text is not free form text.
        Raises CardinalityError if more than one per file.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if not arg_0.file_license_comment_set:
                arg_0.file_license_comment_set = True
                if validations.validate_file_lics_comment(arg_2):
                    arg_0.file(arg_1).license_comment = str_from_text(arg_2)
                else:
                    raise SPDXValueError('File::LicenseComment')
            else:
                raise CardinalityError('File::LicenseComment')
        else:
            raise OrderError('File::LicenseComment')


def Func(arg_0, arg_1, arg_2):
        """Raises OrderError if no package or file defined.
        Raises SPDXValueError if not free form text or NONE or NO_ASSERT.
        Raises CardinalityError if more than one.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if not arg_0.file_copytext_set:
                arg_0.file_copytext_set = True
                if validations.validate_file_cpyright(arg_2):
                    if isinstance(arg_2, string_types):
                        arg_0.file(arg_1).copyright = str_from_text(arg_2)
                    else:
                        arg_0.file(arg_1).copyright = arg_2  # None or NoAssert
                    return True
                else:
                    raise SPDXValueError('File::CopyRight')
            else:
                raise CardinalityError('File::CopyRight')
        else:
            raise OrderError('File::CopyRight')


def Func(arg_0, arg_1, arg_2):
        """Raises OrderError if no package or file defined.
        Raises SPDXValueError if not free form text.
        Raises CardinalityError if more than one.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if not arg_0.file_notice_set:
                arg_0.file_notice_set = True
                if validations.validate_file_notice(arg_2):
                    arg_0.file(arg_1).notice = str_from_text(arg_2)
                else:
                    raise SPDXValueError('File::Notice')
            else:
                raise CardinalityError('File::Notice')
        else:
            raise OrderError('File::Notice')


def Func(arg_0, arg_1, arg_2, arg_3):
        """Sets a file name, uri or home artificat.
        Raises OrderError if no package or file defined.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            arg_0.file(arg_1).add_artifact(arg_2, arg_3)
        else:
            raise OrderError('File::Artificat')


def Func(arg_0):
        """Resets the builder's state to enable building new files."""
        # FIXME: this state does not make sense
        arg_0.file_spdx_id_set = False
        arg_0.file_comment_set = False
        arg_0.file_type_set = False
        arg_0.file_chksum_set = False
        arg_0.file_conc_lics_set = False
        arg_0.file_license_comment_set = False
        arg_0.file_notice_set = False
        arg_0.file_copytext_set = False


def Func(arg_0, arg_1, arg_2):
        """Sets license extracted text.
        Raises SPDXValueError if text is not free form text.
        Raises OrderError if no license ID defined.
        """
        if arg_0.has_extr_lic(arg_1):
            if not arg_0.extr_text_set:
                arg_0.extr_text_set = True
                if validations.validate_is_free_form_text(arg_2):
                    arg_0.extr_lic(arg_1).text = str_from_text(arg_2)
                    return True
                else:
                    raise SPDXValueError('ExtractedLicense::text')
            else:
                raise CardinalityError('ExtractedLicense::text')
        else:
            raise OrderError('ExtractedLicense::text')


def Func(arg_0, arg_1, arg_2):
        """Sets license name.
        Raises SPDXValueError if name is not str or utils.NoAssert
        Raises OrderError if no license id defined.
        """
        if arg_0.has_extr_lic(arg_1):
            if not arg_0.extr_lic_name_set:
                arg_0.extr_lic_name_set = True
                if validations.validate_extr_lic_name(arg_2):
                    arg_0.extr_lic(arg_1).full_name = arg_2
                    return True
                else:
                    raise SPDXValueError('ExtractedLicense::Name')
            else:
                raise CardinalityError('ExtractedLicense::Name')
        else:
            raise OrderError('ExtractedLicense::Name')


def Func(arg_0, arg_1, arg_2):
        """Sets license comment.
        Raises SPDXValueError if comment is not free form text.
        Raises OrderError if no license ID defined.
        """
        if arg_0.has_extr_lic(arg_1):
            if not arg_0.extr_lic_comment_set:
                arg_0.extr_lic_comment_set = True
                if validations.validate_is_free_form_text(arg_2):
                    arg_0.extr_lic(arg_1).comment = str_from_text(arg_2)
                    return True
                else:
                    raise SPDXValueError('ExtractedLicense::comment')
            else:
                raise CardinalityError('ExtractedLicense::comment')
        else:
            raise OrderError('ExtractedLicense::comment')


def Func(arg_0, arg_1, arg_2):
        """Adds a license cross reference.
        Raises OrderError if no License ID defined.
        """
        if arg_0.has_extr_lic(arg_1):
            arg_0.extr_lic(arg_1).add_xref(arg_2)
            return True
        else:
            raise OrderError('ExtractedLicense::CrossRef')


def Func(arg_0):
    """
    Return an ISO-8601 representation of a datetime object.
    """
    return "{0:0>4}-{1:0>2}-{2:0>2}T{3:0>2}:{4:0>2}:{5:0>2}Z".format(
        arg_0.year, arg_0.month, arg_0.day, arg_0.hour,
        arg_0.minute, arg_0.second)


def Func(arg_0, **arg_1):
        """Must be called before parse."""
        arg_0.yacc = arg_2.yacc(module=arg_0, **arg_1)


def Func(arg_0, arg_1):
        """Parses a license list and returns a License or None if it failed."""
        try:
            return arg_0.yacc.Func(arg_1, lexer=arg_0.lex)
        except:
            return None


def Func(arg_0, arg_1, arg_2=True):
    """
    Write an SPDX RDF document.
    - document - spdx.document instance.
    - out - file like object that will be written to.
    Optionally `validate` the document before writing and raise
    InvalidDocumentError if document.validate returns False.
    """

    if arg_2:
        arg_3 = []
        arg_3 = arg_0.validate(arg_3)
        if arg_3:
            raise InvalidDocumentError(arg_3)

    arg_4 = Writer(arg_0, arg_1)
    arg_4.write()


def Func(arg_0, arg_1):
        """
        Return a node representing spdx.checksum.
        """
        arg_2 = BNode()
        arg_3 = (arg_2, RDF.type, arg_0.spdx_namespace.Checksum)
        arg_0.graph.add(arg_3)
        arg_4 = (arg_2, arg_0.spdx_namespace.algorithm, Literal(arg_1.identifier))
        arg_0.graph.add(arg_4)
        arg_5 = (arg_2, arg_0.spdx_namespace.checksumValue, Literal(arg_1.value))
        arg_0.graph.add(arg_5)
        return arg_2


def Func(arg_0, arg_1):
        """
        Traverse conjunctions and disjunctions like trees and return a
        set of all licenses in it as nodes.
        """
        # FIXME: this is unordered!
        arg_2 = set()
        arg_0.Func_helper(arg_1, arg_2)
        return arg_2


def Func(arg_0, arg_1):
        """
        Return a node representing a conjunction of licenses.
        """
        arg_2 = BNode()
        arg_3 = (arg_2, RDF.type, arg_0.spdx_namespace.ConjunctiveLicenseSet)
        arg_0.graph.add(arg_3)
        arg_4 = arg_0.licenses_from_tree(arg_1)
        for arg_5 in arg_4:
            arg_6 = (arg_2, arg_0.spdx_namespace.member, arg_5)
            arg_0.graph.add(arg_6)
        return arg_2


def Func(arg_0, arg_1):
        """
        Handle dependencies for a single file.
        - doc_file - instance of spdx.file.File.
        """
        arg_2 = list(arg_0.graph.triples((None, arg_0.spdx_namespace.fileName, Literal(arg_1.name))))
        if len(arg_2) != 1:
            raise InvalidDocumentError('Could not find dependency subject {0}'.format(arg_1.name))
        arg_3 = arg_2[0][0]
        for arg_4 in arg_1.dependencies:
            arg_5 = list(arg_0.graph.triples((None, arg_0.spdx_namespace.fileName, Literal(arg_4))))
            if len(arg_5) == 1:
                arg_6 = arg_5[0][0]
                arg_7 = (arg_3, arg_0.spdx_namespace.fileDependency, arg_6)
                arg_0.graph.add(arg_7)
            else:
                print('Warning could not resolve file dependency {0} -> {1}'.format(arg_1.name, arg_4))


def Func(arg_0, arg_1):
        """
        Return a review node.
        """
        arg_2 = BNode()
        arg_3 = (arg_2, RDF.type, arg_0.spdx_namespace.Review)
        arg_0.graph.add(arg_3)

        arg_4 = Literal(arg_1.reviewer.to_value())
        arg_0.graph.add((arg_2, arg_0.spdx_namespace.reviewer, arg_4))
        arg_5 = Literal(arg_1.review_date_iso_format)
        arg_6 = (arg_2, arg_0.spdx_namespace.reviewDate, arg_5)
        arg_0.graph.add(arg_6)
        if arg_1.has_comment:
            arg_7 = Literal(arg_1.comment)
            arg_8 = (arg_2, RDFS.comment, arg_7)
            arg_0.graph.add(arg_8)

        return arg_2


def Func(arg_0, arg_1):
        """
        Return an annotation node.
        """
        arg_2 = URIRef(str(arg_1.spdx_id))
        arg_3 = (arg_2, RDF.type, arg_0.spdx_namespace.Annotation)
        arg_0.graph.add(arg_3)

        arg_4 = Literal(arg_1.annotator.to_value())
        arg_0.graph.add((arg_2, arg_0.spdx_namespace.annotator, arg_4))
        arg_5 = Literal(arg_1.annotation_date_iso_format)
        arg_6 = (arg_2, arg_0.spdx_namespace.annotationDate, arg_5)
        arg_0.graph.add(arg_6)
        if arg_1.has_comment:
            arg_7 = Literal(arg_1.comment)
            arg_8 = (arg_2, RDFS.comment, arg_7)
            arg_0.graph.add(arg_8)
        arg_9 = Literal(arg_1.annotation_type)
        arg_10 = (arg_2, arg_0.spdx_namespace.annotationType, arg_9)
        arg_0.graph.add(arg_10)

        return arg_2


def Func(arg_0, arg_1):
        """
        Return a node representing package verification code.
        """
        arg_2 = BNode()
        arg_3 = (arg_2, RDF.type, arg_0.spdx_namespace.PackageVerificationCode)
        arg_0.graph.add(arg_3)
        arg_4 = (arg_2, arg_0.spdx_namespace.packageVerificationCodeValue, Literal(arg_1.verif_code))
        arg_0.graph.add(arg_4)
        arg_5 = map(
            lambda excl: Literal(excl), arg_1.verif_exc_files)
        arg_6 = arg_0.spdx_namespace.packageVerificationCodeExcludedFile
        arg_7 = [(arg_2, arg_6, xcl_file) for xcl_file in arg_5]
        for arg_8 in arg_7:
            arg_0.graph.add(arg_8)
        return arg_2


def Func(arg_0, arg_1, arg_2):
        """
        Write package optional fields.
        """
        arg_0.handle_package_literal_optional(arg_1, arg_2, arg_0.spdx_namespace.versionInfo, 'version')
        arg_0.handle_package_literal_optional(arg_1, arg_2, arg_0.spdx_namespace.packageFileName, 'file_name')
        arg_0.handle_package_literal_optional(arg_1, arg_2, arg_0.spdx_namespace.supplier, 'supplier')
        arg_0.handle_package_literal_optional(arg_1, arg_2, arg_0.spdx_namespace.originator, 'originator')
        arg_0.handle_package_literal_optional(arg_1, arg_2, arg_0.spdx_namespace.sourceInfo, 'source_info')
        arg_0.handle_package_literal_optional(arg_1, arg_2, arg_0.spdx_namespace.licenseComments, 'license_comment')
        arg_0.handle_package_literal_optional(arg_1, arg_2, arg_0.spdx_namespace.summary, 'summary')
        arg_0.handle_package_literal_optional(arg_1, arg_2, arg_0.spdx_namespace.description, 'description')

        if arg_1.has_optional_field('check_sum'):
            arg_3 = arg_0.create_checksum_node(arg_1.check_sum)
            arg_0.graph.add((arg_2, arg_0.spdx_namespace.checksum, arg_3))

        if arg_1.has_optional_field('homepage'):
            arg_4 = URIRef(arg_0.to_special_value(arg_1.homepage))
            arg_5 = (arg_2, arg_0.doap_namespace.homepage, arg_4)
            arg_0.graph.add(arg_5)


def Func(arg_0, arg_1):
        """
        Return a Node representing the package.
        Files must have been added to the graph before this method is called.
        """
        arg_2 = BNode()
        arg_3 = (arg_2, RDF.type, arg_0.spdx_namespace.Package)
        arg_0.graph.add(arg_3)
        # Handle optional fields:
        arg_0.handle_pkg_optional_fields(arg_1, arg_2)
        # package name
        arg_4 = (arg_2, arg_0.spdx_namespace.name, Literal(arg_1.name))
        arg_0.graph.add(arg_4)
        # Package download location
        arg_5 = (arg_2, arg_0.spdx_namespace.downloadLocation, arg_0.to_special_value(arg_1.download_location))
        arg_0.graph.add(arg_5)
        # Handle package verification
        arg_6 = arg_0.package_verif_node(arg_1)
        arg_7 = (arg_2, arg_0.spdx_namespace.packageVerificationCode, arg_6)
        arg_0.graph.add(arg_7)
        # Handle concluded license
        arg_8 = arg_0.license_or_special(arg_1.conc_lics)
        arg_9 = (arg_2, arg_0.spdx_namespace.licenseConcluded, arg_8)
        arg_0.graph.add(arg_9)
        # Handle declared license
        arg_10 = arg_0.license_or_special(arg_1.license_declared)
        arg_11 = (arg_2, arg_0.spdx_namespace.licenseDeclared, arg_10)
        arg_0.graph.add(arg_11)
        # Package licenses from files
        arg_12 = map(lambda el: arg_0.license_or_special(el), arg_1.licenses_from_files)
        arg_13 = arg_0.spdx_namespace.licenseInfoFromFiles
        arg_14 = [(arg_2, arg_13, node) for node in arg_12]
        for arg_15 in arg_14:
            arg_0.graph.add(arg_15)
        # Copyright Text
        arg_16 = arg_0.to_special_value(arg_1.cr_text)
        arg_17 = (arg_2, arg_0.spdx_namespace.copyrightText, arg_16)
        arg_0.graph.add(arg_17)
        # Handle files
        arg_0.handle_package_has_file(arg_1, arg_2)
        return arg_2


def Func(arg_0, arg_1):
        """
        Return node representing pkg_file
        pkg_file should be instance of spdx.file.
        """
        arg_2 = list(arg_0.graph.triples((None, arg_0.spdx_namespace.fileName, Literal(arg_1.name))))
        if len(arg_2) == 1:
            return arg_2[0][0]
        else:
            raise InvalidDocumentError('Func could not' +
                                       ' find file node for file: {0}'.format(arg_1.name))


def Func(arg_0, arg_1, arg_2):
        """
        Add hasFile triples to graph.
        Must be called after files have been added.
        """
        arg_3 = map(arg_0.Func_helper, arg_1.files)
        arg_4 = [(arg_2, arg_0.spdx_namespace.hasFile, node) for node in arg_3]
        for arg_5 in arg_4:
            arg_0.graph.add(arg_5)


def Func(arg_0):
        """
        Add and return the root document node to graph.
        """
        arg_1 = URIRef('http://www.spdx.org/tools#SPDXRef-DOCUMENT')
        # Doc type
        arg_0.graph.add((arg_1, RDF.type, arg_0.spdx_namespace.SpdxDocument))
        # Version
        arg_2 = Literal(str(arg_0.document.version))
        arg_0.graph.add((arg_1, arg_0.spdx_namespace.specVersion, arg_2))
        # Data license
        arg_3 = URIRef(arg_0.document.data_license.url)
        arg_0.graph.add((arg_1, arg_0.spdx_namespace.dataLicense, arg_3))
        arg_4 = URIRef(arg_0.document.name)
        arg_0.graph.add((arg_1, arg_0.spdx_namespace.name, arg_4))
        return arg_1


def Func(arg_0, arg_1):
        """Returns True if the fields are valid according to the SPDX standard.
        Appends user friendly messages to the messages parameter.
        """
        arg_1 = arg_0.Func_creators(arg_1)
        arg_1 = arg_0.Func_created(arg_1)

        return arg_1


def Func(arg_0, arg_1):
        """Checks if value is a special SPDX value such as
        NONE, NOASSERTION or UNKNOWN if so returns proper model.
        else returns value"""
        if arg_1 == arg_0.spdx_namespace.none:
            return utils.SPDXNone()
        elif arg_1 == arg_0.spdx_namespace.noassertion:
            return utils.NoAssert()
        elif arg_1 == arg_0.spdx_namespace.unknown:
            return utils.UnKnown()
        else:
            return arg_1


def Func(arg_0, arg_1):
        """
        Return license comment or None.
        """
        arg_2 = list(arg_0.graph.triples(
            (arg_1, RDFS.comment, None)))
        if len(arg_2) > 1 :
            arg_0.more_than_one_error('extracted license comment')
            return
        elif len(arg_2) == 1:
            return arg_2[0][2]
        else:
            return


def Func(arg_0, arg_1):
        """
        Return an ExtractedLicense object to represent a license object.
        But does not add it to the SPDXDocument model.
        Return None if failed.
        """
        # Grab all possible values
        arg_2 = arg_0.get_extr_license_ident(arg_1)
        arg_3 = arg_0.get_extr_license_text(arg_1)
        arg_4 = arg_0.get_extr_lics_comment(arg_1)
        arg_5 = arg_0.get_extr_lics_xref(arg_1)
        arg_6 = arg_0.get_extr_lic_name(arg_1)

        if not arg_2:
            # Must have identifier
            return

        # Set fields
        # FIXME: the constructor of the license should alwas accept a name
        arg_7 = document.ExtractedLicense(arg_2)
        if arg_3 is not None:
            arg_7.text = arg_3
        if arg_6 is not None:
            arg_7.full_name = arg_6
        if arg_4 is not None:
            arg_7.comment = arg_4
        arg_7.cross_ref = map(lambda x: six.text_type(x), arg_5)
        return arg_7


def Func(arg_0, arg_1):
        """
        Build and return an ExtractedLicense or None.
        Note that this function adds the license to the document.
        """
        arg_2 = arg_0.parse_only_extr_license(arg_1)
        if arg_2 is not None:
            arg_0.doc.add_extr_lic(arg_2)
        return arg_2


def Func(arg_0, arg_1):
        """Returns first found fileName property or None if not found."""
        for arg_2, arg_2, arg_3 in arg_0.graph.triples((arg_1, arg_0.spdx_namespace['fileName'], None)):
            return arg_3
        return


def Func(arg_0, arg_1, arg_2):
        """Sets file dependencies."""
        for arg_3, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_2, None)):
            arg_5 = arg_0.get_file_name(arg_4)
            if arg_5 is not None:
                arg_0.builder.add_file_dep(six.text_type(arg_5))
            else:
                arg_0.error = True
                arg_7 = 'File depends on file with no name'
                arg_0.logger.log(arg_7)


def Func(arg_0, arg_1, arg_2):
        """
        Parse all file contributors and adds them to the model.
        """
        for arg_3, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_2, None)):
            arg_0.builder.add_file_contribution(arg_0.doc, six.text_type(arg_4))


def Func(arg_0, arg_1, arg_2):
        """Sets file notice text."""
        try:
            for arg_3, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_2, None)):
                arg_0.builder.set_file_notice(arg_0.doc, six.text_type(arg_4))
        except CardinalityError:
            arg_0.more_than_one_error('file notice')


def Func(arg_0, arg_1, arg_2):
        """Sets file comment text."""
        try:
            for arg_3, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_2, None)):
                arg_0.builder.set_file_comment(arg_0.doc, six.text_type(arg_4))
        except CardinalityError:
            arg_0.more_than_one_error('file comment')


def Func(arg_0, arg_1, arg_2):
        """Sets file license comment."""
        try:
            for arg_3, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_2, None)):
                arg_0.builder.set_file_license_comment(arg_0.doc, six.text_type(arg_4))
        except CardinalityError:
            arg_0.more_than_one_error('file comments on license')


def Func(arg_0, arg_1, arg_2):
        """Sets file license information."""
        for arg_3, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_2, None)):
            arg_5 = arg_0.handle_lics(arg_4)
            if arg_5 is not None:
                arg_0.builder.set_file_license_in_file(arg_0.doc, arg_5)


def Func(arg_0, arg_1, arg_2):
        """Sets file type."""
        try:
            for arg_3, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_2, None)):
                try:
                    if arg_4.endswith('binary'):
                        arg_4 = 'BINARY'
                    elif arg_4.endswith('source'):
                        arg_4 = 'SOURCE'
                    elif arg_4.endswith('other'):
                        arg_4 = 'OTHER'
                    elif arg_4.endswith('archive'):
                        arg_4 = 'ARCHIVE'
                    arg_0.builder.set_file_type(arg_0.doc, arg_4)
                except SPDXValueError:
                    arg_0.value_error('FILE_TYPE', arg_4)
        except CardinalityError:
            arg_0.more_than_one_error('file type')


def Func(arg_0, arg_1, arg_2):
        """Sets file checksum. Assumes SHA1 algorithm without checking."""
        try:
            for arg_3, arg_4, arg_5 in arg_0.graph.triples((arg_1, arg_2, None)):
                for arg_6, arg_6, arg_7 in arg_0.graph.triples((arg_5, arg_0.spdx_namespace['checksumValue'], None)):
                    arg_0.builder.set_file_chksum(arg_0.doc, six.text_type(arg_7))
        except CardinalityError:
            arg_0.more_than_one_error('File checksum')


def Func(arg_0, arg_1, arg_2):
        """Sets file licenses concluded."""
        try:
            for arg_3, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_2, None)):
                if (arg_4, RDF.type, arg_0.spdx_namespace['ConjunctiveLicenseSet']) in arg_0.graph:
                    arg_5 = arg_0.handle_conjunctive_list(arg_4)
                    arg_0.builder.set_concluded_license(arg_0.doc, arg_5)

                elif (arg_4, RDF.type, arg_0.spdx_namespace['DisjunctiveLicenseSet']) in arg_0.graph:
                    arg_5 = arg_0.handle_disjunctive_list(arg_4)
                    arg_0.builder.set_concluded_license(arg_0.doc, arg_5)

                else:
                    try:
                        arg_5 = arg_0.handle_lics(arg_4)
                        arg_0.builder.set_concluded_license(arg_0.doc, arg_5)
                    except SPDXValueError:
                        arg_0.value_error('FILE_SINGLE_LICS', arg_4)
        except CardinalityError:
            arg_0.more_than_one_error('file {0}'.format(arg_2))


def Func(arg_0, arg_1):
        """Returns review date or None if not found.
        Reports error on failure.
        Note does not check value format.
        """
        arg_2 = list(arg_0.graph.triples((arg_1, arg_0.spdx_namespace['reviewDate'], None)))
        if len(arg_2) != 1:
            arg_0.error = True
            arg_4 = 'Review must have exactlyone review date'
            arg_0.logger.log(arg_4)
            return
        return six.text_type(arg_2[0][2])


def Func(arg_0, arg_1):
        """Returns annotation comment or None if found none or more than one.
        Reports errors.
        """
        arg_2 = list(arg_0.graph.triples((arg_1, RDFS.comment, None)))
        if len(arg_2) > 1:
            arg_0.error = True
            arg_4 = 'Annotation can have at most one comment.'
            arg_0.logger.log(arg_4)
            return
        else:
            return six.text_type(arg_2[0][2])


def Func(arg_0, arg_1):
        """Returns annotation date or None if not found.
        Reports error on failure.
        Note does not check value format.
        """
        arg_2 = list(arg_0.graph.triples((arg_1, arg_0.spdx_namespace['annotationDate'], None)))
        if len(arg_2) != 1:
            arg_0.error = True
            arg_4 = 'Annotation must have exactly one annotation date.'
            arg_0.logger.log(arg_4)
            return
        return six.text_type(arg_2[0][2])


def Func(arg_0, arg_1):
        """
        Parse creators, created and comment.
        """
        for arg_2, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_0.spdx_namespace['creator'], None)):
            try:
                arg_5 = arg_0.builder.create_entity(arg_0.doc, six.text_type(arg_4))
                arg_0.builder.add_creator(arg_0.doc, arg_5)
            except SPDXValueError:
                arg_0.value_error('CREATOR_VALUE', arg_4)

        for arg_2, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_0.spdx_namespace['created'], None)):
            try:
                arg_0.builder.set_created_date(arg_0.doc, six.text_type(arg_4))
            except SPDXValueError:
                arg_0.value_error('CREATED_VALUE', arg_4)
            except CardinalityError:
                arg_0.more_than_one_error('created')
                break

        for arg_2, arg_3, arg_4 in arg_0.graph.triples((arg_1, RDFS.comment, None)):
            try:
                arg_0.builder.set_creation_comment(arg_0.doc, six.text_type(arg_4))
            except CardinalityError:
                arg_0.more_than_one_error('CreationInfo comment')
                break
        for arg_2, arg_3, arg_4 in arg_0.graph.triples((arg_1, arg_0.spdx_namespace['licenseListVersion'], None)):
            try:
                arg_0.builder.set_lics_list_ver(arg_0.doc, six.text_type(arg_4))
            except CardinalityError:
                arg_0.more_than_one_error('licenseListVersion')
                break
            except SPDXValueError:
                arg_0.value_error('LL_VALUE', arg_4)


def Func(arg_0, arg_1):
        """
        Parses the External Document ID, SPDX Document URI and Checksum.
        """
        for arg_2, arg_3, arg_4 in arg_0.graph.triples(
                (arg_1,
                 arg_0.spdx_namespace['externalDocumentId'],
                 None)):
            try:
                arg_0.builder.set_ext_doc_id(arg_0.doc, six.text_type(arg_4))
            except SPDXValueError:
                arg_0.value_error('EXT_DOC_REF_VALUE', 'External Document ID')
                break

        for arg_2, arg_3, arg_4 in arg_0.graph.triples(
                (arg_1,
                 arg_0.spdx_namespace['spdxDocument'],
                 None)):
            try:
                arg_0.builder.set_spdx_doc_uri(arg_0.doc, six.text_type(arg_4))
            except SPDXValueError:
                arg_0.value_error('EXT_DOC_REF_VALUE', 'SPDX Document URI')
                break

        for arg_2, arg_3, arg_5 in arg_0.graph.triples(
                (arg_1, arg_0.spdx_namespace['checksum'], None)):
            for arg_6, arg_6, arg_7 in arg_0.graph.triples(
                    (arg_5, arg_0.spdx_namespace['checksumValue'], None)):
                try:
                    arg_0.builder.set_chksum(arg_0.doc, six.text_type(arg_7))
                except SPDXValueError:
                    arg_0.value_error('EXT_DOC_REF_VALUE', 'Checksum')
                    break


def Func(arg_0, arg_1):
        """
        Validate the package fields.
        Append user friendly error messages to the `messages` list.
        """
        arg_1 = arg_0.Func_checksum(arg_1)
        arg_1 = arg_0.Func_optional_str_fields(arg_1)
        arg_1 = arg_0.Func_mandatory_str_fields(arg_1)
        arg_1 = arg_0.Func_files(arg_1)
        arg_1 = arg_0.Func_mandatory_fields(arg_1)
        arg_1 = arg_0.Func_optional_fields(arg_1)

        return arg_1


def Func(arg_0, arg_1, arg_2, arg_3):
        """Helper for validate_mandatory_str_field and
        validate_optional_str_fields"""
        for arg_4 in arg_1:
            arg_5 = getattr(arg_0, arg_4)
            if arg_5 is not None:
                # FIXME: this does not make sense???
                arg_6 = getattr(arg_5, '__str__', None)
                if not callable(arg_6):
                    arg_3 = arg_3 + [
                        '{0} must provide __str__ method.'.format(arg_5)
                    ]
                    # Continue checking.
            elif not arg_2:
                arg_3 = arg_3 + [
                    'Package {0} can not be None.'.format(arg_4)
                ]

        return arg_3


def Func(arg_0, arg_1, arg_2):
        """Sets document comment, Raises CardinalityError if
        comment already set.
        """
        if not arg_0.doc_comment_set:
            arg_0.doc_comment_set = True
            arg_1.comment = arg_2
        else:
            raise CardinalityError('Document::Comment')


def Func(arg_0, arg_1, arg_2):
        """
        Sets the external document reference's check sum, if not already set.
        chk_sum - The checksum value in the form of a string.
        """
        if arg_2:
            arg_1.ext_document_references[-1].check_sum = checksum.Algorithm(
                'SHA1', arg_2)
        else:
            raise SPDXValueError('ExternalDocumentRef::Checksum')


def Func(arg_0, arg_1, arg_2):
        """Sets the package's source information, if not already set.
        text - Free form text.
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_source_info_set:
            arg_0.package_source_info_set = True
            arg_1.package.source_info = arg_2
            return True
        else:
            raise CardinalityError('Package::SourceInfo')


def Func(arg_0, arg_1, arg_2):
        """Sets the package's verification code excluded file.
        Raises OrderError if no package previously defined.
        """
        arg_0.assert_package_exists()
        arg_1.package.add_exc_file(arg_2)


def Func(arg_0, arg_1, arg_2):
        """Set's the package summary.
        Raises CardinalityError if summary already set.
        Raises OrderError if no package previously defined.
        """
        arg_0.assert_package_exists()
        if not arg_0.package_summary_set:
            arg_0.package_summary_set = True
            arg_1.package.summary = arg_2
        else:
            raise CardinalityError('Package::Summary')


def Func(arg_0, arg_1, arg_2):
        """Sets the file check sum, if not already set.
        chk_sum - A string
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if not arg_0.file_chksum_set:
                arg_0.file_chksum_set = True
                arg_0.file(arg_1).chk_sum = checksum.Algorithm('SHA1', arg_2)
                return True
            else:
                raise CardinalityError('File::CheckSum')
        else:
            raise OrderError('File::CheckSum')


def Func(arg_0, arg_1, arg_2):
        """
        Raises OrderError if no package or file defined.
        Raises CardinalityError if more than one per file.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if not arg_0.file_license_comment_set:
                arg_0.file_license_comment_set = True
                arg_0.file(arg_1).license_comment = arg_2
                return True
            else:
                raise CardinalityError('File::LicenseComment')
        else:
            raise OrderError('File::LicenseComment')


def Func(arg_0, arg_1, arg_2):
        """Raises OrderError if no package or no file defined.
        Raises CardinalityError if more than one comment set.
        """
        if arg_0.has_package(arg_1) and arg_0.has_file(arg_1):
            if not arg_0.file_comment_set:
                arg_0.file_comment_set = True
                arg_0.file(arg_1).comment = arg_2
                return True
            else:
                raise CardinalityError('File::Comment')
        else:
            raise OrderError('File::Comment')


def Func(arg_0, arg_1, arg_2):
        """Sets the annotation comment. Raises CardinalityError if
        already set. OrderError if no annotator defined before.
        """
        if len(arg_1.annotations) != 0:
            if not arg_0.annotation_comment_set:
                arg_0.annotation_comment_set = True
                arg_1.annotations[-1].comment = arg_2
                return True
            else:
                raise CardinalityError('AnnotationComment')
        else:
            raise OrderError('AnnotationComment')


def Func(arg_0, arg_1, arg_2):
        """Sets the annotation type. Raises CardinalityError if
        already set. OrderError if no annotator defined before.
        """
        if len(arg_1.annotations) != 0:
            if not arg_0.annotation_type_set:
                if arg_2.endswith('annotationType_other'):
                    arg_0.annotation_type_set = True
                    arg_1.annotations[-1].annotation_type = 'OTHER'
                    return True
                elif arg_2.endswith('annotationType_review'):
                    arg_0.annotation_type_set = True
                    arg_1.annotations[-1].annotation_type = 'REVIEW'
                    return True
                else:
                    raise SPDXValueError('Annotation::AnnotationType')
            else:
                raise CardinalityError('Annotation::AnnotationType')
        else:
            raise OrderError('Annotation::AnnotationType')


def Func(arg_0, arg_1):
        """
        Validate all fields of the document and update the
        messages list with user friendly error messages for display.
        """
        arg_1 = arg_0.Func_version(arg_1)
        arg_1 = arg_0.Func_data_lics(arg_1)
        arg_1 = arg_0.Func_name(arg_1)
        arg_1 = arg_0.Func_spdx_id(arg_1)
        arg_1 = arg_0.Func_namespace(arg_1)
        arg_1 = arg_0.Func_ext_document_references(arg_1)
        arg_1 = arg_0.Func_creation_info(arg_1)
        arg_1 = arg_0.Func_package(arg_1)
        arg_1 = arg_0.Func_extracted_licenses(arg_1)
        arg_1 = arg_0.Func_reviews(arg_1)

        return arg_1


def Func(arg_0):
  '''Decorator to synchronize function.'''
  arg_0.__lock__ = threading.Lock()
  def synced_func(*arg_2, **arg_3):
    with arg_0.__lock__:
      return arg_0(*arg_2, **arg_3)
  return synced_func