# method to detect scenario prop_two
#
#
#
# constellation for "wasDerivedFrom"
#
# scenario prop_two:
# ?s prov:wasDerivedFrom BOUND .
#
#
#
# look_for e.g. "http://www.w3.org/ns/prov#wasDerivedFrom"


def scenario_prop_two_occurrences(json_object, look_for, bound_variables):
    where = json_object["where"]

    # find scenario prop_two

    result = 0

    # multiple bgp (basic graph patterns)
    for where_part in where:

        if "type" in where_part and where_part["type"] == "bgp":
            for triple in where_part["triples"]:

                if (triple["subject"]["termType"] == "Variable") and ((triple["subject"]["value"])
                                                                      not in bound_variables.__str__()):
                    # on property paths, there also could be no termType
                    if ("termType" in triple["predicate"]):
                        if (triple["predicate"]["termType"] == "NamedNode" and
                              look_for in triple["predicate"]["value"])\
                                or (look_for == triple["predicate"]["value"] and look_for in str(bound_variables)
                                    and triple["predicate"]["termType"] == "Variable"):
                            # TODO: BETTER METHOD, THAN JUST THIS STR -> use regex with x numbers behind the "P" also for other scenarios):

                            if (triple["object"]["termType"] == "NamedNode") or \
                                    ((triple["object"]["value"]) in bound_variables.__str__()
                                        and triple["object"]["termType"] == "Variable"):

                                result += 1

    return result

# method to detect scenario prop_two
#
#
#
# constellation for "wasDerivedFrom"
#
# scenario prop_two:
# ?s prov:wasDerivedFrom BOUND .
#
#
#
# look_for e.g. "http://www.w3.org/ns/prov#wasDerivedFrom"


def scenario_prop_two_occurrences(json_object, look_for, bound_variables):
    where = json_object["where"]

    # find scenario prop_two

    result = 0

    # multiple bgp (basic graph patterns)
    for where_part in where:

        if "type" in where_part and where_part["type"] == "bgp":
            for triple in where_part["triples"]:

                if (triple["subject"]["termType"] == "Variable") and ((triple["subject"]["value"])
                                                                      not in bound_variables.__str__()):
                    # on property paths, there also could be no termType
                    if ("termType" in triple["predicate"]):
                        if (triple["predicate"]["termType"] == "NamedNode" and
                              look_for in triple["predicate"]["value"])\
                                or (look_for == triple["predicate"]["value"] and look_for in str(bound_variables)
                                    and triple["predicate"]["termType"] == "Variable"):
                            # TODO: BETTER METHOD, THAN JUST THIS STR -> use regex with x numbers behind the "P" also for other scenarios):

                            if (triple["object"]["termType"] == "NamedNode") or \
                                    ((triple["object"]["value"]) in bound_variables.__str__()
                                        and triple["object"]["termType"] == "Variable"):

                                result += 1

    return result

# method to detect scenario prop_two # # # # constellation for "wasDerivedFrom" # # scenario prop_two: # ?s prov:wasDerivedFrom BOUND . # # # # look_for e.g. "http://www.w3.org/ns/prov#wasDerivedFrom" # find scenario prop_two # multiple bgp (basic graph patterns) # on property paths, there also could be no termType # TODO: BETTER METHOD, THAN JUST THIS STR -> use regex with x numbers behind the "P" also for other scenarios):