ORKG Comparisons
The comparisons client is a special client of the ORKG that handles publishing comparisons. For that reason it needs to be connected to the simcomp service of the Open Research Knowledge Graph (ORKG).
If you instantiate the ORKG client using a web address or host environment name (Hosts.PRODUCTION, Hosts.SANDBOX, or Hosts.INCUBATING), the corresponding simcomp_host is automatically assigned.
However, if you are running the ORKG locally then you need to specify simcomp_host. See Host for details.
Publishing a comparison in the ORKG involves several steps. First, a resource in the graph is which represents the comparison and contains relations to all metadata of the comparison. Second, the comparison itself is computed using the SimComp service. Last, the comparison with its configuration is stored within the SimComp service for persistence.
You can access the comparisons client directly to do the following:
Create comparisons
The create method allows you to create a new comparison with all the necessary parameters. This is particularly useful when you need to specify detailed configuration for your comparison.
# Create a new comparison with required parameters
comparison = orkg.comparisons.create(
title="Comparison of Neural Network Architectures",
description="Performance analysis of different neural network architectures",
contributions=["R726088", "R709123"],
research_fields=["R132"],
config={
"contributions": ["R726088", "R709123"],
"predicates": [],
"transpose": False,
"type": "MERGE",
},
data={
"contributions": [
{
"active": True,
"id": "R726088",
"label": "Contribution 1",
"paper_id": "R726086",
"paper_label": "Paper 1",
"paper_year": 2023,
},
{
"active": True,
"id": "R709123",
"label": "Contribution 1",
"paper_id": "R709120",
"paper_label": "Paper 2",
"paper_year": 2010,
},
],
"predicates": [
{
"active": True,
"id": "P32",
"label": "research problem",
"n_contributions": 2,
"similar_predicates": ["P15"],
}
],
"data": {
"P32": [
[
{
"_class": "resource",
"classes": ["Problem"],
"id": "R705584",
"label": "Dataset used in wind energy potential assessment",
"path": ["R726086", "P32"],
"path_labels": ["Contribution 1", "research problem"],
}
]
]
},
}
)
>>> (Success)
{
"id":"R18750",
"label":"Comparison of Neural Network Architectures",
"created_at":"2023-06-12T09:35:22.291Z",
"classes":[
"Comparison"
],
"shared":1,
"created_by":"00000000-0000-0000-0000-000000000000",
"_class":"resource"
}
The create method supports additional optional parameters: - sdgs: List of sustainable development goal IDs - visualizations: List of visualization IDs - references: List of reference strings - organizations: List of organization IDs - observatories: List of observatory IDs - is_anonymized: Boolean flag (default: False) - extraction_method: String, one of: “UNKNOWN”, “MANUAL”, “AUTOMATIC” (default: “UNKNOWN”) - authors: List of author objects with name and other information
Publish comparisons
The python package offers an abstraction over the steps needed to publish a comparison.
# First create the comparison
comparison = orkg.comparisons.create(
title="Comparison of Machine Learning Models",
description="Performance comparison of different ML models",
contributions=["R339476", "R339468"],
research_fields=["R132"],
config={
"contributions": ["R339476", "R339468"],
"predicates": [],
"transpose": False,
"type": "MERGE",
},
data={
# Comparison data here
}
)
# Then publish it
published = orkg.comparisons.publish(
comparison_id=comparison.content["id"],
subject="Comparison of Machine Learning Models",
description="Performance comparison of different ML models",
authors=[{"name": "Smith, John"}, {"name": "Doe, Jane"}],
assign_doi=False
)
>>> (Success)
{
"id":"R15780",
"label":"Comparison of Machine Learning Models",
"created_at":"2023-06-12T15:04:07.692Z",
"classes":[
"Comparison"
],
"shared":1,
"created_by":"00000000-0000-0000-0000-000000000000",
"_class":"resource"
}
The publish method requires these parameters: - comparison_id: ID of the comparison to publish - subject: The subject/title of the comparison - description: The description of the comparison - authors: List of author objects with name information - assign_doi: Whether to assign a DOI (Digital Object Identifier) to the comparison (default: False)
Get comparisons by research field ID
You can get a list of comparisons from within a particular research field. You may optionally include comparisons from subfields as well. If the response is an empty list, it means the research field has no comparisons (or that the given ID does not correspond to a resource with the ‘ResearchField’ class label).
### Fetch comparisons by research field id
# research_field_id: the id of the research field
# include_subfields: True/False whether to include comparisons from subfields, default is False (optional)
# page: the page number (optional)
# size: number of items per page (optional)
# sort: key to sort on (optional)
# desc: true/false to sort desc (optional)
orkg.comparisons.in_research_field('R132', include_subfields=True, size=3)
>>> (Success)
[
{
'id': 'R8340',
'label': 'Semi-supervised author name disambiguation',
'classes': ['Comparison']
},
{
'id': 'R8341',
'label': 'Semi-supervised author name disambiguation',
'classes': ['Comparison']
},
{
'id': 'R8342',
'label': 'Ontologies for describing scholarly articles',
'classes': ['Comparison']
}
]