Examples on interacting with Classes through GraphQL¶
Overview¶
A Class is a collection of similar things that are classified. A class may be directly associated with VARS concept but it isn't required to be so for machine learning purposes. For example, a class may represent a machine learning-centric class, e.g. a pose of a concept, a machine learning friendly name for a class, etc.
Classes are created during loading if they do not already exist, and are owned by a particular user.
In [1]:
Copied!
import requests
# This is the endpoint for the GraphQL API. On a production installation it might be http://<yourservername>/api .
API_URL = "http://localhost:4000/graphql"
import requests
# This is the endpoint for the GraphQL API. On a production installation it might be http:///api .
API_URL = "http://localhost:4000/graphql"
In [2]:
Copied!
def get_classes():
query = """ {
classes {
id
concept
user_id
}
}
"""
reply = (requests.post(API_URL, json={'query': query}).json())
return(reply['data']['classes'])
def get_classes():
query = """ {
classes {
id
concept
user_id
}
}
"""
reply = (requests.post(API_URL, json={'query': query}).json())
return(reply['data']['classes'])
In [3]:
Copied!
get_classes()
get_classes()
Out[3]:
[{'id': 1, 'concept': 'Bathyraja trachura', 'user_id': 1}, {'id': 2, 'concept': 'Bathyraja abyssicola', 'user_id': 1}, {'id': 3, 'concept': 'Pteraster', 'user_id': 1}, {'id': 4, 'concept': 'Merluccius productus', 'user_id': 1}, {'id': 5, 'concept': 'Luidia foliolata', 'user_id': 1}, {'id': 6, 'concept': 'Stylasterias forreri', 'user_id': 1}, {'id': 7, 'concept': 'Porifera', 'user_id': 1}, {'id': 8, 'concept': 'Neptunea-Buccinum Complex', 'user_id': 1}, {'id': 9, 'concept': 'Munidopsis', 'user_id': 1}, {'id': 10, 'concept': 'Asbestopluma monticola', 'user_id': 1}, {'id': 11, 'concept': 'Octocorallia', 'user_id': 1}, {'id': 12, 'concept': 'Pennatulacea', 'user_id': 1}, {'id': 13, 'concept': 'Asbestopluma rickettsi', 'user_id': 1}, {'id': 14, 'concept': 'Paragorgia', 'user_id': 1}, {'id': 15, 'concept': 'Chionoecetes tanneri', 'user_id': 1}, {'id': 16, 'concept': 'Sebastolobus', 'user_id': 1}, {'id': 17, 'concept': 'Psolus squamatus', 'user_id': 1}, {'id': 18, 'concept': 'Hormathiidae', 'user_id': 1}, {'id': 19, 'concept': 'Asteroidea', 'user_id': 1}, {'id': 20, 'concept': 'Gersemia juliepackardae', 'user_id': 1}, {'id': 21, 'concept': 'Brisingida', 'user_id': 1}, {'id': 22, 'concept': 'Peniagone', 'user_id': 1}, {'id': 23, 'concept': 'Holothuroidea', 'user_id': 1}, {'id': 24, 'concept': 'Hippasteria', 'user_id': 1}, {'id': 25, 'concept': 'Pannychia moseleyi', 'user_id': 1}, {'id': 26, 'concept': 'Isididae', 'user_id': 1}, {'id': 27, 'concept': 'Swiftia', 'user_id': 1}, {'id': 28, 'concept': 'Mediaster aequalis', 'user_id': 1}, {'id': 29, 'concept': 'Hymenaster', 'user_id': 1}, {'id': 30, 'concept': 'Rathbunaster californicus', 'user_id': 1}, {'id': 31, 'concept': 'Embassichthys bathybius', 'user_id': 1}, {'id': 32, 'concept': 'Pleuronectiformes', 'user_id': 1}, {'id': 33, 'concept': 'Solasteridae', 'user_id': 1}, {'id': 34, 'concept': 'Pyrosoma detritus', 'user_id': 1}, {'id': 35, 'concept': 'Octopus rubescens', 'user_id': 1}, {'id': 36, 'concept': 'equipment', 'user_id': 1}, {'id': 37, 'concept': 'Asthenactis fisheri', 'user_id': 1}, {'id': 38, 'concept': 'Crossaster', 'user_id': 1}, {'id': 39, 'concept': 'Swiftia simplex', 'user_id': 1}, {'id': 40, 'concept': 'Sebastes', 'user_id': 1}, {'id': 41, 'concept': 'Anoplopoma fimbria', 'user_id': 1}, {'id': 42, 'concept': 'Scotoplanes globosa', 'user_id': 1}, {'id': 43, 'concept': 'Actinernus', 'user_id': 1}, {'id': 44, 'concept': 'Microstomus pacificus', 'user_id': 1}, {'id': 45, 'concept': 'Akoya platinum', 'user_id': 1}, {'id': 46, 'concept': 'Gastropoda', 'user_id': 1}, {'id': 47, 'concept': 'Paragorgia arborea', 'user_id': 1}, {'id': 48, 'concept': 'Swiftia kofoidi', 'user_id': 1}, {'id': 49, 'concept': 'Keratoisis', 'user_id': 1}]
In [4]:
Copied!
def get_ordered_classes():
query = """ {
classOrderedByConcept(take: 10) {
id
concept
created_at
}
}
"""
reply = (requests.post(API_URL, json={'query': query}).json())
return(reply['data']['classOrderedByConcept'])
get_ordered_classes()
def get_ordered_classes():
query = """ {
classOrderedByConcept(take: 10) {
id
concept
created_at
}
}
"""
reply = (requests.post(API_URL, json={'query': query}).json())
return(reply['data']['classOrderedByConcept'])
get_ordered_classes()
Out[4]:
[{'id': 43, 'concept': 'Actinernus', 'created_at': '2022-06-13T16:25:03.671Z'}, {'id': 45, 'concept': 'Akoya platinum', 'created_at': '2022-06-13T16:25:03.710Z'}, {'id': 41, 'concept': 'Anoplopoma fimbria', 'created_at': '2022-06-13T16:25:03.572Z'}, {'id': 10, 'concept': 'Asbestopluma monticola', 'created_at': '2022-06-13T16:25:03.080Z'}, {'id': 13, 'concept': 'Asbestopluma rickettsi', 'created_at': '2022-06-13T16:25:03.105Z'}, {'id': 19, 'concept': 'Asteroidea', 'created_at': '2022-06-13T16:25:03.166Z'}, {'id': 37, 'concept': 'Asthenactis fisheri', 'created_at': '2022-06-13T16:25:03.447Z'}, {'id': 2, 'concept': 'Bathyraja abyssicola', 'created_at': '2022-06-13T16:25:03.021Z'}, {'id': 1, 'concept': 'Bathyraja trachura', 'created_at': '2022-06-13T16:25:02.992Z'}, {'id': 21, 'concept': 'Brisingida', 'created_at': '2022-06-13T16:25:03.187Z'}]
Copyright (c) 2022, MBARI