Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,

I have to iterate through a list of functions in python and decide which ones to call based on whether the arguments for each function are present in a JSON file. After a function is called, its return value is also added to the JSON file. Since a function's output value can end up being the input value for another function, I iterate through the list of functions multiple times.

The structure of the JSON file looks something like this:

{
    "town": {
        "name": "town name"
        "buildings": {
            "park": {
                "address": "address 1"
            },
            "mall": {
                "address": "address 3"
                "stores": [ist of dicts],
                "openingHours": "10:00-23:00"
            }
        }
    }
}


Examples of functions would be findSportsStores(stores) and isParkOpen(openingHours). A function can ask for arguments from specific buildings and/or from the parent node (town).

In this case only the first function would run since the argument stores is present. The second wouldn't since the argument openingHours is not present in park in the JSON file.

What I have tried:

My first attempt to implement this argument search was by using the name of the argument being searched and pointing it to a specific node in the JSON.

The problem is: how do I find these arguments without hardcoding the rules? For example for the above situation when iterating through the JSON file the argument openingHours in mall should not be confused with the argument the specific function is looking for (openingHours in park). The JSON file in itself depends on the user so it can have way more buildings with more information and identically named keys in different buildings (for example address), so I definitely want to avoid a hardcoded solution when looking for each function's arguments since the solution has to be flexible due to the user-dependent JSON file as input.

I have read about knowledge graphs and was wondering, would that be an appropriate solution for this argument search? If so, how would I proceed?

If not, any pointers to a better solution would be highly appreciated.

Thanks.
Posted
Updated 31-Oct-21 7:13am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900