Skip to content

Commit

Permalink
Change knowledgebase synset metadata matching algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
cgokmen committed Jan 23, 2024
1 parent fa8e2f8 commit cddd712
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 15 deletions.
29 changes: 14 additions & 15 deletions bddl/knowledge_base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,46 +266,45 @@ def matching_ready_objects(self) -> Set[Object]:
@cached_property
def required_meta_links(self) -> Set[str]:
properties = {prop.name: json.loads(prop.parameters) for prop in self.properties}
predicates = {pred.name.lower() for pred in self.used_in_predicates}

if 'substance' in properties:
return set() # substances don't need any meta links

# TODO: Remove this
# If we are not task relevant, we don't need any meta links
if not self.n_task_required:
return set()
# if not self.n_task_required:
# return set()

required_links = set()

# If we are a heatSource or togglesource, we need to have certain links
for property in ['heatSource', 'coldSource']:
if property in properties:
if 'requires_toggled_on' in properties[property] and properties[property]['requires_toggled_on']:
required_links.add('togglebutton')

if 'requires_inside' not in properties[property] or not properties[property]['requires_inside']:
required_links.add('heatSource')
if 'requires_inside' in properties[property] and properties[property]['requires_inside']:
continue
required_links.add('heatSource')

if self.is_used_as_fillable and 'fillable' in properties:
if 'fillable' in properties:
required_links.add('fillable')

if 'toggledon' in predicates and 'toggleable' in properties:
if 'toggleable' in properties:
required_links.add('togglebutton')

# TODO: Enable this.
# if 'particleSink' in properties:
# required_links.add('fluidSink')

particle_pairs = [
('particleSink', 'fluidsink'),
('particleSource', 'fluidsource'),
('particleApplier', 'particleapplier'),
('particleRemover', 'particleremover'),
]
for property, meta_link in particle_pairs:
if property in properties and 'method' in properties[property] and properties[property]['method'] == 1: # only the projection method (1) needs this
if property in properties:
if 'method' in properties[property] and properties[property]['method'] != 1: # not projection
continue
required_links.add(meta_link)

if 'slicer' in properties:
required_links.add('slicer')

return required_links

@cached_property
Expand Down
52 changes: 52 additions & 0 deletions notebooks/Meta Link Support.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading BDDL knowledge base... This may take a few seconds.\n",
"[nltk_data] Downloading package wordnet to /home/cgokmen/nltk_data...\n",
"[nltk_data] Package wordnet is already up-to-date!\n"
]
}
],
"source": [
"from bddl.knowledge_base import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "omnigibson",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit cddd712

Please sign in to comment.