Esempio n. 1
0
def drawLinkBetween2 (title: str, operation: str, source: str, destination: str):
    #TODO normalize and rewrite to query by id

    if TextOperations.hasEnoughSlots(operation, 2):
        links = [source, destination]
        link = Link(title, operation, links)
        saveLink(link)
Esempio n. 2
0
def registerAnnotatedLink(title: str, text: str):
    #TODO normalize
    annotatedText = TextOperations.annotatedText(text)
    reducedText = annotatedText.getReducedText()
    sublinks = annotatedText.sublinks
    for sublink in sublinks:
        registerLink(sublink.title, sublink.text, sublink.links)

    registerLinkFromUnformattedText(title, reducedText)
Esempio n. 3
0
def extendTagByMany (tag: str, newLinks: list):
    #TODO normalize and rewrite to query by id
    tagLink = getLink(tag)

    amountOfNewSlots = len(newLinks)

    newOperation = TextOperations.extendEnumerationByX(tagLink.operation, amountOfNewSlots)
    tagLink.operation = newOperation

    tagLink.links = tagLink.links + newLinks

    editLink(tag, tagLink)
Esempio n. 4
0
def collectMentionsForTag(tagTitle: str):
    #TODO normalize
    mentions = seekManyByLink(tagTitle)
    link = getLink(tagTitle)
    mentionsToAdd = []
    for mention in mentions:
        alreadyInLink = False
        for alias in mention.alias:
            if alias in link.links:
                alreadyInLink = True
                break
        if alreadyInLink == False:
            mentionsToAdd.append(mention.getName())

    if mentionsToAdd:
        newOperation = TextOperations.extendEnumerationByX(link.operation, len(mentionsToAdd))
        newLinks = link.links + mentionsToAdd
        link.operation = newOperation
        link.links = newLinks

        editLinkByID(link.id, link)
Esempio n. 5
0
def registerSimpleLink(jsonInput: object) -> list:
    """
    Creates and saves a new link to the database, using a json as input. Validates that the json has the required format. The created link will either have just an alias (an empty link), or be complete (alias, plus operation and links). The function returns the created link.

    Parameters
    ----------
    name : jsonInput
        A json provided as input, which will be validated against the TextOperations.validateJSON function (an "alias" property is the only requirement).

    Raises
    ------
    TypeError
        If jsonInput parameter doesn't pass the validation, an error is raised.
    """    
    if (TextOperations.validateJSON(jsonInput)):
        linkAlias = jsonInput["alias"]
        link = Link(linkAlias)
        if propertyExists(jsonInput, "text"):
            link.fromUnformattedText(jsonInput["text"])
        createdLinks = saveLink(link)
        return createdLinks
    else:
        raise TypeError("Inadequate json input format. JSON input must have a name attribute, at least.")
Esempio n. 6
0
 def fromUnformattedText(self, text):
     linkedText = TextOperations.extractLinks(text)
     self.operation = linkedText.text
     self.links = linkedText.links
Esempio n. 7
0
def enumerateLinks (title: str, operationBeginning: str, titles: list):
    #TODO normalize and rewrite to query by id
    operation = TextOperations.generateOperation(operationBeginning, len(titles))
    link = Link (title, operation, titles)
    saveLink(link)
Esempio n. 8
0
def groupLinks (title: str, operation: str, titles: list):
    #TODO normalize and raise exception if conditions aren't fulfilled and rewrite to query by id
    if TextOperations.hasEnoughSlots(operation, len(titles)):
        link = Link(title, operation, titles)
        saveLink(link)