def test_get_all_arguments_with_text_by_statement_id(self): res = lib.get_all_arguments_with_text_by_statement_id(0) self.assertEqual(res, []) results = { 47: 'we should close public swimming pools because our swimming pools are very old and it would take a major investment to repair them', 48: 'Other participants said that we should close public swimming pools because our swimming pools are very old and it would take a major investment to repair them. You did not agree with this because schools need the swimming pools for their sports lessons.', 49: 'we should close public swimming pools does not hold, because the rate of non-swimmers is too high' } res = lib.get_all_arguments_with_text_by_statement_id(38) self.assertEqual(len(res), 3) for r in res: self.assertIn(r['uid'], results)
def find_statements_fn(request): """ Receives search requests, queries database to find all occurrences and returns these results with the correct URL to get directly access to the location in the discussion. :param request: :return: json conform dictionary of all occurrences """ api_data = dict() api_data["issue"] = request.matchdict["issue"] api_data["mode"] = request.matchdict["type"] api_data["value"] = request.matchdict["value"] results = dbas.fuzzy_search(request, api_data=api_data) issue_uid = api_data["issue"] return_dict = dict() return_dict["distance_name"] = results["distance_name"] return_dict["values"] = [] for statement in results["values"]: statement_uid = statement["statement_uid"] statement["issue"] = { "uid": issue_uid, "slug": resolve_issue_uid_to_slug(issue_uid) } statement["url"] = url_to_statement( api_data["issue"], statement_uid) # TODO I think I do not use this any more statement["arguments"] = get_all_arguments_with_text_by_statement_id( statement_uid) return_dict["values"].append(statement) return return_dict
def get_all_references_by_reference_text(ref_text=None): """ Query database for all occurrences of a given reference text. Prepare list with information about used issue, author and a url to the statement. :param ref_text: Reference text :return: list of used references """ if ref_text: refs = list() matched: List[StatementReference] = DBDiscussionSession.query( StatementReference).filter( StatementReference.text == ref_text).all() for reference in matched: textversion: TextVersion = reference.statement.get_textversion() statement_url = url_to_statement(reference.issue, reference.statement) refs.append({ "reference": reference, "arguments": get_all_arguments_with_text_by_statement_id( reference.statement_uid), "statement": { "uid": reference.statement_uid, "url": statement_url, "text": textversion.content } }) return refs
def get_all_references_by_reference(reference: StatementReference) -> DataReferenceWithStatement: """ Query database for all occurrences of a given reference text. Prepare a DTO with all arguments, which are referring to this reference. :param reference: Reference which is being queried. :return: list of used references """ matched: List[StatementReference] = DBDiscussionSession.query(StatementReference).filter( StatementReference.text == reference.text, StatementReference.host == reference.host, StatementReference.path == reference.path).all() arguments: List[List[dict]] = [get_all_arguments_with_text_by_statement_id(reference.statement_uid) for reference in matched] unique_arguments = _extract_unique_arguments(flatten(arguments)) return DataReferenceWithStatement(reference, unique_arguments)
def get_all_references_by_reference_text(ref_text=None): """ Query database for all occurrences of a given reference text. Prepare list with information about used issue, author and a url to the statement. :param ref_text: Reference text :return: list of used references """ if ref_text: refs = list() matched = DBDiscussionSession.query(StatementReferences).filter_by( reference=ref_text).all() for reference in matched: user = DBDiscussionSession.query(User).get(reference.author_uid) issue = DBDiscussionSession.query(Issue).get(reference.issue_uid) textversion = DBDiscussionSession.query(TextVersion).get( reference.statement_uid) statement_url = url_to_statement(issue.uid, reference.statement_uid) refs.append({ "reference": extract_reference_information(reference), "author": extract_author_information(user), "issue": extract_issue_information(issue), "arguments": get_all_arguments_with_text_by_statement_id( reference.statement_uid), "statement": { "uid": reference.statement_uid, "url": statement_url, "text": textversion.content } }) return refs
def __init__(self, reference: StatementReference): self.reference = reference self.arguments = get_all_arguments_with_text_by_statement_id( reference.statement_uid) self.statement_url = url_to_statement(reference.issue, reference.statement)