NCATSTranslator / ReasonerAPI

NCATS Biomedical Translator Reasoners Standard API
34 stars 28 forks source link

Edges should not be required in the knowledge_graph schema #77

Closed srensi closed 4 years ago

srensi commented 5 years ago

Is there some reason we are requiring graphs to have edges? Singletons and collections of disconnected vertices are perfectly valid graphs!

Edit: Or at least we shouldn't require the edge list to be non empty. Basically I am trying to implement the scenario described above, and the spec doesn't allow it.

Update: I was able to get around it by adding self edges. I mean It works, but...

patrickkwang commented 5 years ago

My understanding is that we require that there be an edges field, which is a list, but that list can be empty. There's a way, using minItems, to enforce that a list not be empty, but we don't use that. How are you running into this restriction?

srensi commented 5 years ago

I get it when posting JSON containing knowledge graph with an empty edge list. I end up getting the error message shown below.

What I think goes on is that Message object with no KG is ok (not required). But as soon as you add a KG to a Message object you get the following chain of dependencies:

KG: nodes (required), edges (required) Node: id (required) Edge: source_id (required), target_id (required)

So basically, if it sees a knowledge_graph in the message it expects to see a source_id and target_id somewhere (maybe). Adding just one self edge (i.e. n1--n1) made the problem go away.

validation error:  {
    'nodes': [{
        'uri': 'vasopressin',
        'name': 'vasopressin',
        'categories': ['Mention'],
        'id': 'vasopressin'
    }],
    'edges': []
}
is valid under each of {
    'x-scope': ['', '#/components/schemas/Query', '#/components/schemas/Message'],
    'type': 'object',
    'properties': {
        'url': {
            'type': 'string',
            'description': 'URL that provides programmatic access to the remote knowledge graph',
            'example': 'http://robokop.renci.org/api/kg'
        },
        'credentials': {
            'type': 'array',
            'description': 'Credentials needed for programmatic access to the remote knowledge graph',
            'items': {
                'x-scope': ['', '#/components/schemas/Query', '#/components/schemas/Message', '#/components/schemas/RemoteKnowledgeGraph'],
                'required': ['password', 'username'],
                'type': 'object',
                'properties': {
                    'username': {
                        'type': 'string',
                        'description': 'Username needed for programmatic access to the remote knowledge graph'
                    },
                    'password': {
                        'type': 'string',
                        'description': 'Password needed for programmatic access to the remote knowledge graph'
                    }
                },
                'additionalProperties': True,
                'description': 'Credentials needed for programmatic access to the remote knowledge graph'
            }
        }
    },
    'additionalProperties': True,
    'description': 'A thought graph associated with this result that is not repeated here, but stored elsewhere in a way that can be remotely accessed by the reader of this Message'
}, {
    'x-scope': ['', '#/components/schemas/Query', '#/components/schemas/Message'],
    'required': ['edges', 'nodes'],
    'type': 'object',
    'properties': {
        'nodes': {
            'type': 'array',
            'description': 'List of nodes in the KnowledgeGraph',
            'items': {
                'x-scope': ['', '#/components/schemas/Query', '#/components/schemas/Message', '#/components/schemas/KnowledgeGraph'],
                'required': ['id'],
                'type': 'object',
                'properties': {
                    'id': {
                        'type': 'string',
                        'description': 'CURIE identifier for this node',
                        'example': 'OMIM:603903'
                    },
                    'name': {
                        'type': 'string',
                        'description': 'Formal name of the entity',
                        'example': 'Haptoglobin'
                    },
                    'type': {
                        'type': 'array',
                        'description': 'Entity type of this node (e.g., protein, disease, etc.)',
                        'example': ['protein'],
                        'items': {
                            'type': 'string'
                        }
                    }
                },
                'additionalProperties': True,
                'description': 'A node in the thought subgraph'
            }
        },
        'edges': {
            'type': 'array',
            'description': 'List of edges in the KnowledgeGraph',
            'items': {
                'x-scope': ['', '#/components/schemas/Query', '#/components/schemas/Message', '#/components/schemas/KnowledgeGraph'],
                'required': ['id', 'source_id', 'target_id'],
                'type': 'object',
                'properties': {
                    'id': {
                        'type': 'string',
                        'description': "Local identifier for this node which is unique within this KnowledgeGraph, and perhaps within the source reasoner's knowledge graph",
                        'example': '553903'
                    },
                    'type': {
                        'type': 'string',
                        'description': 'Higher-level relationship type of this edge',
                        'example': 'affects'
                    },
                    'source_id': {
                        'type': 'string',
                        'description': 'Corresponds to the @id of source node of this edge',
                        'example': 'https://omim.org/entry/603903'
                    },
                    'target_id': {
                        'type': 'string',
                        'description': 'Corresponds to the @id of target node of this edge',
                        'example': 'https://www.uniprot.org/uniprot/P00738'
                    }
                },
                'additionalProperties': True,
                'description': 'An edge in the thought subgraph linking two nodes'
            }
        }
    },
    'additionalProperties': True,
    'description': 'A thought graph associated with this result. This will commonly be a linear path subgraph from one concept to another, but related items aside of the path may be included.'
}
patrickkwang commented 5 years ago

The error message here is a direct result of #48. I'm surprised that adding a self edge fixes this. The error message seems disconnected from the issues you're describing.