def get_by_items(items): """Get list of orders which contains given items. Args: items (List[Item]): list of items to look for. Returns: List[Order]: list of orders containing at leas one of the provided items """ values = " ".join(map(lambda x: f"<{x.iri}>", items)) i1 = "VALUES ?item { " + values + " } .\n" i2 = f"?oi <{has_item.iri}> ?item .\n" i3 = f"?ord <{has_ordered_items.iri}> ?oi .\n" query = "SELECT DISTINCT ?ord WHERE { " + i1 + i2 + i3 + " }" return list(default_world.sparql_query(query))
def get_by_items(items): """Get list of locations storing given items. Args: items (List[Item]): list of items to locate items. Returns: List[RackLocation]: list of locations storing items """ values = " ".join(map(lambda x: f"<{x.iri}>", items)) i1 = "VALUES ?item { " + values + " } .\n" i2 = f"?inv <{has_item.iri}> ?item .\n" i3 = f"?inv <{has_location.iri}> ?loc .\n" query = "SELECT DISTINCT ?loc WHERE { " + i1 + i2 + i3 + " }" return list(default_world.sparql_query(query))
def get_by_orders(orders): """Get list of items included in given orders. Args: orders (List[Order]): list of orders to search. Returns: List[Item]: list of items included in orders. """ values = " ".join(map(lambda x: f"<{x.iri}>", orders)) i1 = "VALUES ?ord { " + values + " } .\n" i2 = f"?ord <{has_ordered_items.iri}> ?oi .\n" i3 = f"?oi <{has_item.iri}> ?item .\n" query = "SELECT DISTINCT ?item WHERE { " + i1 + i2 + i3 + " }" return list(default_world.sparql_query(query))
def get_by_locations(locations): """Get list of items stored at given location. Args: locations (List[RackLocation]): list of locations to look for. Returns: List[Item]: list of items stored at locations """ # TODO: Check inventory date values = " ".join(map(lambda x: f"<{x.iri}>", locations)) i1 = "VALUES ?loc { " + values + " } .\n" i2 = f"?inv <{has_location.iri}> ?loc .\n" i3 = f"?inv <{has_item.iri}> ?item .\n" query = "SELECT DISTINCT ?item WHERE { " + i1 + i2 + i3 + " }" return list(default_world.sparql_query(query))
def get_by_locations(locations): """Get list of orders which potentially access given locations. Args: locations (List[RackLocation]): list of locations to inspect Returns: List[Order]: list of orders containing items stored at given locations """ values = " ".join(map(lambda x: f"<{x.iri}>", locations)) i1 = "VALUES ?loc { " + values + " } .\n" i2 = f"?inv <{has_location.iri}> ?loc .\n" i3 = f"?inv <{has_item.iri}> ?item .\n" i4 = f"?oi <{has_item.iri}> ?item .\n" i5 = f"?ord <{has_ordered_items.iri}> ?oi .\n" query = "SELECT DISTINCT ?ord WHERE { " + i1 + i2 + i3 + i4 + i5 + " }" return list(default_world.sparql_query(query))
def get_by_orders(orders): """Get list of locations which are potentially accessed by given orders. Args: locations (List[Order]): list of locations to inspect Returns: List[RackLocation]: list of locations containing ordered items """ # TODO: speed up this query (reverse property???) values = " ".join(map(lambda x: f"<{x.iri}>", orders)) i1 = "VALUES ?ord { " + values + " } .\n" i2 = f"?ord <{has_ordered_items.iri}> ?oi .\n" i3 = f"?oi <{has_item.iri}> ?item .\n" i4 = f"?inv <{has_item.iri}> ?item .\n" i5 = f"?inv <{has_location.iri}> ?loc .\n" query = "SELECT DISTINCT ?loc WHERE { " + i1 + i2 + i3 + i4 + i5 + " }" return list(default_world.sparql_query(query))