Ejemplo n.º 1
0
def multiple() -> List[dict]:
    """Finds multiple triple modifiers

    :return: A list of triple modifiers
    """

    return generic.resolve(multiple)()
Ejemplo n.º 2
0
def candidates(
    label: str,
    limit: Union[int, None] = 10,
    language: str = 'en',
    query_limit: int = None,
    perfect_match_only: bool = False,
    graph: str = default_graph_uri
) -> Dict[str, List[Dict[str, Union[str, List[str]]]]]:
    """Finds candidates of entities given a partial or full label

    This endpoint function returns three list of candidates:
        The 'exact_matches' are candidates which labels match the search label perfectly.
        The 'first_matches' are candidates which labels start with the search label
        The 'partial_matches' are candidates which labels partially match the search label

    :param label: The partial or full search label
    :param limit: The maximum number of candidates in each of the response lists
    :param language: A language filter for the candidates' labels
    :param query_limit: The maximum number of candidates specified in the database query command
    :param perfect_match_only: Finds only candidates that exactly match the search label
    :param graph: Graph URI
    :return: The three lists of candidates ({"exact_matches": ..., "first_matches": ..., "partial_matches": ...})
    """

    return generic.resolve(candidates)(graph, label, limit, language,
                                       query_limit, perfect_match_only)
Ejemplo n.º 3
0
def single(request: Request, triple: dict, original_triple: dict) -> str:
    """Edits a document containing an edit-triple modifier

    :param request: Django REST Framework's Request object (to get the issuer information)
    :param triple: The replacing triple (subject, predicate, object)
           :ex: ["http://dbpedia.org/resource/Barack_Obama", "http://dbpedia.org/property/birthplace", "http://dbpedia.org/resource/United_States"]
    :param original_triple: The original triple to be edited (subject, predicate, object)
           :ex: ["http://dbpedia.org/resource/Barack_Obama", "http://dbpedia.org/property/birthplace", "http://dbpedia.org/resource/Hawaii"]
    :return: Edited document's id
    """

    document = dict({
        'action':
        'edit',
        'created':
        datetime.now(),
        'issuer':
        CustomUser.objects.get_by_natural_key(request.user).username,
        'api':
        os.environ['UWKGM_API_VERSION'],
        'triple':
        triple,
        'originalTriple':
        original_triple
    })
    return generic.resolve(single)(document)
Ejemplo n.º 4
0
def single(document_id: str) -> int:
    """Deletes a triple modifier

    :param document_id: Document id of the triple modifier
    :return: The number of triple modifiers removed in this transaction
    """

    return generic.resolve(single)(document_id)
Ejemplo n.º 5
0
def single(triple: Tuple[str, str, str],
           graph: str = default_graph_uri) -> str:
    """Deletes a triple from the graph database

    :param triple: Entities of (subject, predicate, object)
    :param graph: Graph URI
    :return: Deleting status
    """

    return generic.resolve(single)(triple, graph)
Ejemplo n.º 6
0
def single(triple: Tuple[str, str, str],
           graph: str = default_graph_uri) -> bool:
    """Checks whether a triple exists in the graph

    :param triple: Entities of (subject, predicate, object)
    :param graph: Graph URI
    :return: True if the triple exists in the graph
    """

    return generic.resolve(single)(triple, graph)
Ejemplo n.º 7
0
def single(request: Request, document: dict) -> str:
    """Adds a document containing the given text

    :param document: A dictionary containing the text
           :ex: {"text": "Barack Obama was born in Hawaii"}
    :param request: Django REST Framework's Request object (to get the issuer information)
    :return: The added document id
    """

    document['datetime'] = datetime.now()
    document['issuer'] = CustomUser.objects.get_by_natural_key(request.user).username
    document['api'] = os.environ['UWKGM_API_VERSION']
    return generic.resolve(single)(document)
Ejemplo n.º 8
0
def single(entity: str,
           as_element: str = None,
           limit: int = 10000,
           graph: str = default_graph_uri) -> Dict[str, List[Dict[str, str]]]:
    """Finds triples which the given entity is a part of (as subject, predicate, object, or any)

    :param entity: An entity to find the triples
    :param as_element: Find triples where the entity is their 'subject', 'predicate', or 'object' ('None' will ignore this filter)
    :param limit: The maximum number of returned triples
    :param graph: Graph URI
    :return: Lists of triples pertaining to the entity's role ({'subject': [...], 'predicate': [...], 'object': [...]})
    """

    return generic.resolve(single)(graph, entity, as_element, limit)
Ejemplo n.º 9
0
def single(request: Request, triple: dict) -> str:
    """Deletes a document containing a delete-triple modifier

    :param request: Django REST Framework's Request object (to get the issuer information)
    :param triple: A triple to delete from the graph
           :ex: ["http://dbpedia.org/resource/Barack_Obama", "http://dbpedia.org/property/birthplace", "http://dbpedia.org/resource/Hawaii"]
    :return: Deleted document's id
    """

    document = dict({'action': 'delete',
                     'created': datetime.now(),
                     'issuer': CustomUser.objects.get_by_natural_key(request.user).username,
                     'api': os.environ['UWKGM_API_VERSION'],
                     'triple': triple})
    return generic.resolve(single)(document)
Ejemplo n.º 10
0
def single(request: Request, triple: dict, text_id: str = None) -> str:
    """Adds a document containing an add-triple modifier

    :param request: Django REST Framework's Request object (to get the issuer information)
    :param triple: (subject, predicate, object)
           :ex: ["http://dbpedia.org/resource/Barack_Obama", "http://dbpedia.org/property/birthplace", "http://dbpedia.org/resource/Hawaii"]
    :param text_id: If the triple was extracted from a text, 'text_id' stores the reference to the original text.
    :return: Added document's id
    """

    document = dict({'action': 'add',
                     'created': datetime.now(),
                     'issuer': CustomUser.objects.get_by_natural_key(request.user).username,
                     'api': os.environ['UWKGM_API_VERSION'],
                     'triple': triple})

    if text_id is not None:
        document['textId'] = text_id

    return generic.resolve(single)(document)
Ejemplo n.º 11
0
def auto() -> int:
    """Commits triple modifiers that have not been committed before to the graph database

    :return: The number of triple modifiers committed in this transaction
    """
    return generic.resolve(auto)()