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)
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)
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)
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)
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.")
def fromUnformattedText(self, text): linkedText = TextOperations.extractLinks(text) self.operation = linkedText.text self.links = linkedText.links
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)
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)