Esempio n. 1
0
    def post(self):
        """
        Biolink Model Relations
        ---
        tags: [schema]
        description: Get valid relations in the biolink model.
        responses:
            '200':
                description: Array of relations
                content:
                    application/json:
                        schema:
                          type: array
                          items:
                            type: string

        """
        result = {}
        try:
            concept_model = ConceptModel("biolink-model")
            result = sorted(list(concept_model.relations_by_name.keys()))
            logging.debug(result)
        except Exception as e:
            #traceback.print_exc (e)
            result = self.handle_exception(e)
        return self.response(result)
Esempio n. 2
0
    def post(self):
        """
        query
        ---
        tag: validation
        description: TranQL concept model relations query.
        requestBody:
            description: Input message
            required: true
            content:
                application/json:
                    schema:
                        type: object
                        properties:
                            query:
                                type: string
        responses:
            '200':
                description: Success
                content:
                    text/plain:
                        schema:
                            type: string
                            example: "Successfully validated"
            '400':
                description: Malformed message
                content:
                    text/plain:
                        schema:
                            type: string

        """
        result = {}
        try:
            concept_model = ConceptModel("biolink-model")
            result = sorted(list(concept_model.relations_by_name.keys()))
            logging.debug(result)
        except Exception as e:
            #traceback.print_exc (e)
            result = self.handle_exception(e)
        return result
Esempio n. 3
0
File: api.py Progetto: patlsc/tranql
    def post(self):
        """
        query
        ---
        tag: validation
        description: TranQL Query
        requestBody:
            description: Input message
            required: true
            content:
                application/json:
                    schema:
                        type: object
                        properties:
                            query:
                                type: string
        responses:
            '200':
                description: Success
                content:
                    text/plain:
                        schema:
                            type: string
                            example: "Successfully validated"
            '400':
                description: Malformed message
                content:
                    text/plain:
                        schema:
                            type: string

        """
        concept_model = ConceptModel("biolink-model")
        concepts = sorted(list(concept_model.by_name.keys()))
        logging.debug(concepts)
        return concepts
Esempio n. 4
0
class Query:
    """ Model a query. 
    TODO:
       - Model queries with arrows in both diretions.
       - Model predicates
       - Model arbitrary shaped graphs.
    """
    """ Arrows in the query. """
    back_arrow = "<-"
    forward_arrow = "->"
    """ The biolink model. Will use for query validation. """
    concept_model = ConceptModel("biolink-model")

    def __init__(self):
        self.order = []
        self.arrows = []
        self.concepts = {}
        self.disable = False

    def add(self, key):
        """ Add a token in the question graph to this query object. """
        if key == self.forward_arrow or key == self.back_arrow:
            """ It's a forward arrow, no predicate. """
            self.arrows.append(Edge(direction=key))
        elif isinstance(key, Concept):
            self.order.append(key.name)
            self.concepts[key.name] = key
        elif isinstance(key, Edge):
            self.arrows.append(key)
        elif isinstance(key, list) and len(key) == 3:
            if key[2].endswith(self.forward_arrow):
                self.arrows.append(
                    Edge(direction=self.forward_arrow, predicate=key[1]))
            elif key[0].startswith(self.back_arrow):
                self.arrows.append(
                    Edge(direction=self.back_arrow, predicate=key[1]))
        else:
            """ It's a concept identifier, potentially named. """
            type_name = key
            name = key
            if ':' in key:
                if key.count(':') > 1:
                    raise IllegalConceptIdentifierError(
                        f"Illegal concept id: {key}")
                name, type_name = key.split(':')
            self.order.append(name)
            """ Verify the type name is in the model we have. """
            assert self.concept_model.get(type_name) != None
            assert type_name in self.concept_model, f"Error: Concept {type_name} is not in the concept model."
            self.concepts[name] = Concept(name=name, type_name=type_name)

    def __getitem__(self, key):
        return self.concepts[key]

    def __setitem__(self, key, value):
        raise ValueError("Not implemented")

    def __delitem__(self, key):
        del self.concepts[key]

    def __contains__(self, key):
        return key in self.concepts

    def __repr__(self):
        return f"{self.concepts} | {self.arrows}"