Make unique identifiers for components of the block and write to files.

    :param blocks: Blocks of sentences (likely the output of
                   ``textprocessing.getBlocks``).
    :type blocks: list
    :param target: Target to write to the background file (another option might
                   be ``blockContainsTarget(+BID,+SID).``).
    :type target: str.
    :param treeDepth: Depth of the tree.
    :type treeDepth: str.
    :param nodeSize: Maximum size of each node in the tree.
    :type nodeSize: str.
    :param numOfClauses: Number of clauses in total.
    :type numOfClauses: str.

    .. note:: This is a function that writes *facts*, presently there is no
      way to distinguish between these and positive/negatives examples.

    Example:

    .. code-block:: python

                    from rnlp.textprocessing import getSentences
                    from rnlp.textprocessing import getBlocks
                    from rnlp.parse import makeIdentifiers

                    example = "Hello there. How are you? I am fine."

                    sentences = getSentences(example)
                    # ['Hello there', 'How are you', 'I am fine']

                    blocks = getBlocks(sentences, 2)
                    # with 1: [['Hello there'], ['How are you'], ['I am fine']]
                    # with 2: [['Hello there', 'How are you'], ['I am fine']]
                    # with 3: [['Hello there', 'How are you', 'I am fine']]

                    makeIdentifiers(blocks)
                    # 100%|██████████████████████| 2/2 [00:00<00:00, 18.49it/s]

def makeIdentifiers(blocks, target="sentenceContainsTarget(+SID,+WID).",
                    treeDepth="3", nodeSize="3", numOfClauses="8"):
    """
    Make unique identifiers for components of the block and write to files.

    :param blocks: Blocks of sentences (likely the output of
                   ``textprocessing.getBlocks``).
    :type blocks: list
    :param target: Target to write to the background file (another option might
                   be ``blockContainsTarget(+BID,+SID).``).
    :type target: str.
    :param treeDepth: Depth of the tree.
    :type treeDepth: str.
    :param nodeSize: Maximum size of each node in the tree.
    :type nodeSize: str.
    :param numOfClauses: Number of clauses in total.
    :type numOfClauses: str.

    .. note:: This is a function that writes *facts*, presently there is no
      way to distinguish between these and positive/negatives examples.

    Example:

    .. code-block:: python

                    from rnlp.textprocessing import getSentences
                    from rnlp.textprocessing import getBlocks
                    from rnlp.parse import makeIdentifiers

                    example = "Hello there. How are you? I am fine."

                    sentences = getSentences(example)
                    # ['Hello there', 'How are you', 'I am fine']

                    blocks = getBlocks(sentences, 2)
                    # with 1: [['Hello there'], ['How are you'], ['I am fine']]
                    # with 2: [['Hello there', 'How are you'], ['I am fine']]
                    # with 3: [['Hello there', 'How are you', 'I am fine']]

                    makeIdentifiers(blocks)
                    # 100%|██████████████████████| 2/2 [00:00<00:00, 18.49it/s]
    """

    blockID, sentenceID, wordID = 1, 0, 0

    print("Creating background file...")

    _writeBk(target=target, treeDepth=treeDepth,
             nodeSize=nodeSize, numOfClauses=numOfClauses)

    print("Creating identifiers from the blocks...")

    nBlocks = len(blocks)
    for block in tqdm(blocks):

        _writeBlock(block, blockID)

        sentenceID = 1
        nSentences = len(block)
        beginning = nSentences/float(3)
        ending = (2*nSentences)/float(3)

        for sentence in block:

            if sentenceID < nSentences:
                # mode: nextSentenceInBlock(blockID, sentenceID, sentenceID).
                ps = "nextSentenceInBlock(" + str(blockID) + "," + \
                     str(blockID) + "_" + str(sentenceID) + "," + \
                     str(blockID) + "_" + str(sentenceID+1) + ")."
                _writeFact(ps)

            if sentenceID < beginning:
                # mode: earlySentenceInBlock(blockID, sentenceID).
                ps = "earlySentenceInBlock(" + str(blockID) + "," + \
                     str(blockID) + "_" + str(sentenceID) + ")."
                _writeFact(ps)
            elif sentenceID > ending:
                # mode: lateSentenceInBlock(blockID, sentenceID).
                ps = "lateSentenceInBlock(" + str(blockID) + "," + \
                     str(blockID) + "_" + str(sentenceID) + ")."
                _writeFact(ps)
            else:
                # mode: midWaySentenceInBlock(blockID, sentenceID).
                ps = "earlySentenceInBlock(" + str(blockID) + "," + \
                     str(blockID) + "_" + str(sentenceID) + ")."
                _writeFact(ps)

            # mode: sentenceInBlock(sentenceID, blockID).
            ps = "sentenceInBlock(" + str(blockID) + "_" + str(sentenceID) + \
                 "," + str(blockID) + ")."
            _writeFact(ps)
            _writeSentenceInBlock(sentence, blockID, sentenceID)

            wordID = 1
            tokens = nltk.word_tokenize(sentence)
            nWords = len(tokens)
            wBeginning = nWords/float(3)
            wEnding = (2*nWords)/float(3)

            for word in tokens:

                """
                if word == "He":
                    pos = open("pos.txt","a")
                    word = str(blockID)+"_"+str(sentenceID)+"_"+str(wordID)
                    sentence = str(blockID)+"_"+str(sentenceID)
                    pos.write("sentenceContainsTarget("+sentence+","+word+").\n")
                    pos.close()
                else:
                    neg = open("neg.txt","a")
                    word = str(blockID)+"_"+str(sentenceID)+"_"+str(wordID)
                    sentence = str(blockID)+"_"+str(sentenceID)
                    neg.write("sentenceContainsTarget("+sentence+","+word+").\n")
                    neg.close()
                """

                # mode: wordString(wordID, #str).
                ps = "wordString(" + str(blockID) + "_" + str(sentenceID) + \
                     "_" + str(wordID) + "," + "'" + str(word) + "')."
                _writeFact(ps)

                # mode: partOfSpeechTag(wordID, #POS).
                POS = nltk.pos_tag([word])[0][1]
                ps = "partOfSpeech(" + str(blockID) + "_" + str(sentenceID) + \
                     "_" + str(wordID) + "," + '"' + str(POS) + '").'
                _writeFact(ps)

                # mode: nextWordInSentence(sentenceID, wordID, wordID).
                if wordID < nWords:
                    ps = "nextWordInSentence(" + str(blockID) + "_" + \
                         str(sentenceID) + "," + str(blockID) + "_" + \
                         str(sentenceID) + "_" + str(wordID) + "," + \
                         str(blockID) + "_" + str(sentenceID) + "_" + \
                         str(wordID+1) + ")."
                    _writeFact(ps)

                if wordID < wBeginning:
                    # mode: earlyWordInSentence(sentenceID, wordID).
                    ps = "earlyWordInSentence(" + str(blockID) + "_" + \
                         str(sentenceID) + "," + str(blockID) + "_" + \
                         str(sentenceID) + "_" + str(wordID) + ")."
                    _writeFact(ps)
                elif wordID > wEnding:
                    # mode: lateWordInSentence(sentenceID< wordID).
                    ps = "lateWordInSentence(" + str(blockID) + "_" + \
                         str(sentenceID) + "," + str(blockID) + "_" + \
                         str(sentenceID) + "_" + str(wordID) + ")."
                    _writeFact(ps)
                else:
                    # mode: midWayWordInSentence(sentenceID, wordID).
                    ps = "midWayWordInSentence(" + str(blockID) + "_" + \
                         str(sentenceID) + "," + str(blockID) + "_" + \
                         str(sentenceID) + "_" + str(wordID) + ")."
                    _writeFact(ps)

                # mode: wordInSentence(wordID, sentenceID).
                ps = "wordInSentence(" + str(blockID) + "_" + \
                     str(sentenceID) + "_" + str(wordID) + "," + \
                     str(blockID) + "_" + str(sentenceID) + ")."
                _writeFact(ps)
                _writeWordFromSentenceInBlock(word, blockID,
                                              sentenceID, wordID)
                wordID += 1
            sentenceID += 1
        blockID += 1