Get all attributes of a variable. Returns (None, "Observation: [...]").
(self, variable: Variable)
| 146 | return new_variable, rtn_str |
| 147 | |
| 148 | def get_attributes(self, variable: Variable): |
| 149 | """ |
| 150 | Get all attributes of a variable. |
| 151 | Returns (None, "Observation: [...]"). |
| 152 | """ |
| 153 | cache_key = (self.task_id, hash(variable)) |
| 154 | |
| 155 | if cache_key in attribute_cache: |
| 156 | out_relations = attribute_cache[cache_key] |
| 157 | else: |
| 158 | program = variable.program |
| 159 | processed_code = postprocess_raw_code(program) |
| 160 | sparql_query = lisp_to_sparql(processed_code) |
| 161 | |
| 162 | clauses = sparql_query.split("\n") |
| 163 | new_clauses = [clauses[0], "SELECT DISTINCT ?rel\nWHERE {\n?x ?rel ?obj .\n{"] |
| 164 | new_clauses.extend(clauses[1:]) |
| 165 | new_clauses.append("}\n}") |
| 166 | new_query = '\n'.join(new_clauses) |
| 167 | |
| 168 | out_relations = self.sparql_executor.execute_query(new_query) |
| 169 | out_relations = list(set(out_relations).intersection(set(attributes))) |
| 170 | attribute_cache[cache_key] = out_relations |
| 171 | variable_attributes_cache[variable] = out_relations |
| 172 | |
| 173 | rtn_str = f"Observation: [{', '.join(out_relations)}]" |
| 174 | return None, rtn_str |
| 175 | |
| 176 | def argmax(self, variable: Variable, attribute: str): |
| 177 | """ |
no test coverage detected