Get the union of two variables :param variable1: a variable :param variable2: a variable :return: a list of union
(variable1: set, variable2: set, sparql_executor)
| 122 | |
| 123 | |
| 124 | def union(variable1: set, variable2: set, sparql_executor): # will create a new variable |
| 125 | """ |
| 126 | Get the union of two variables |
| 127 | :param variable1: a variable |
| 128 | :param variable2: a variable |
| 129 | :return: a list of union |
| 130 | """ |
| 131 | if variable1.type != variable2.type: |
| 132 | raise ValueError("union: two variables must have the same type") |
| 133 | |
| 134 | if not isinstance(variable1, Variable) or not isinstance(variable2, Variable): |
| 135 | raise ValueError("union: variable must be a variable") |
| 136 | |
| 137 | rtn_str = f"Observation: variable ##, which are instances of {variable1.type}" |
| 138 | new_variable = Variable(variable1.type, f"(OR {variable1.program} {variable2.program})") |
| 139 | return new_variable, rtn_str |
| 140 | |
| 141 | |
| 142 | def count(variable: Variable, sparql_executor): |