Get the intersection of two variables :param variable1: a variable :param variable2: a variable :return: a list of intersection
(variable1: Variable, variable2: Variable, sparql_executor)
| 104 | |
| 105 | |
| 106 | def intersection(variable1: Variable, variable2: Variable, sparql_executor): # will create a new variable |
| 107 | """ |
| 108 | Get the intersection of two variables |
| 109 | :param variable1: a variable |
| 110 | :param variable2: a variable |
| 111 | :return: a list of intersection |
| 112 | """ |
| 113 | if variable1.type != variable2.type: |
| 114 | raise ValueError("intersection: two variables must have the same type") |
| 115 | |
| 116 | if not isinstance(variable1, Variable) or not isinstance(variable2, Variable): |
| 117 | raise ValueError("intersection: variable must be a variable") |
| 118 | |
| 119 | rtn_str = f"Observation: variable ##, which are instances of {variable1.type}" |
| 120 | new_variable = Variable(variable1.type, f"(AND {variable1.program} {variable2.program})") |
| 121 | return new_variable, rtn_str |
| 122 | |
| 123 | |
| 124 | def union(variable1: set, variable2: set, sparql_executor): # will create a new variable |