# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['bodge']

package_data = \
{'': ['*']}

install_requires = \
['brickschema>=0.5.1,<0.6.0', 'rdflib>=6.0.2,<7.0.0']

setup_kwargs = {
    'name': 'brick-bodge',
    'version': '0.2.0',
    'description': 'Rule-based framework for building Brick models from simple functions',
    'long_description': '# Rule-Based Model Builder\n\nThis repository implements an experimental rule-based approach to creating Brick models (or really any RDF graph) from variably-structured metadata sources.\nThe APIs and interfaces in this repository may change drastically with little notice, and documentation is sparse! That said, this is fast emerging as my favorite way for creating Brick models from arbitrary sources.\n\nThe key idea is to write small functions that generate part of a Brick graph when certain conditions are met on the input data. The input data is structured as a sequence of key-value documents, called `row`s. It is usually straightforward to turn some source data into a sequence of key-value documents, so this is a natural "intermediate representation" (IR) for arbitrary metadata sources.\n\nThe framework defined in this repository provides a number of simple "rule conditions" for triggering these functions which produce parts of the Brick graph. These rule conditions are designed to make it easier to deal with heterogeneously-structured input data.\n\n## Rule Conditions\n\nEach condition is implemented as a Python decorator. Decorated functions should take a single argument which is the "row" (a Python `dict`)  that matches the conditions defined by the decorator\n\n`tags`: triggers the rule when all of the keys are present\n\n```python\n@tags("AHU")\ndef add_ahu(row):\n    ahu_name = row.get("AHU")\n    G.add((BLDG[ahu_name], A, BRICK.AHU))\n    G.add((BLDG[ahu_name], RDFS.label, Literal(row.get("AHU"))))\n```\n\n---\n\n`oneof`: triggers the rule when at least one of the provided keys is present\n\n```python\npoint_types = {\n    "alarm variable": BRICK.Alarm,\n    "air volume": BRICK.Supply_Air_Flow_Sensor,\n    "differential pressure status sensor": BRICK.Differential_Pressure_Sensor,\n    "discharge air pressure sensor": BRICK.Discharge_Air_Static_Pressure_Sensor,\n    "fan speed reset": BRICK.Speed_Reset_Command,\n    "zone temp": BRICK.Zone_Air_Temperature_Sensor,\n    "zone temp setpoint": BRICK.Zone_Air_Temperature_Setpoint,\n}\n@oneof(*point_types.keys())\ndef define_point(row):\n    for tag, brickclass in point_types.items():\n        if tag in row:\n            sensor = row.get(tag)\n            G.add((BLDG[sensor], A, brickclass))\n```\n\n---\n\n`values`: triggers the rule when the row has the given key-value pairs\n\n```python\n@values({"Category": "Level", "ModelObject": "IfcBuildingStorey"})\ndef add_floors(row):\n    floor_id = EX[row["ModelID"]]\n    G.add((floor_id, RDFS.label, Literal(row["Name"])))\n    G.add((floor_id, A, BRICK.Floor))\n    G.add((floor_id, BRICK.elevation, [\n        (BRICK.value, Literal(float(row["Elevation"]))),\n        (BRICK.unit, units["linear"]),\n    ]))\n```\n\n---\n\n`_and_`: triggers the rule when all of the given conditions are met. Sorry for the funky syntax; ideally the decorators compose easily but this will take some work to figure out how to do\n\n\n```python\n@_and_([tags, "AHU", "uuid"], [oneof, *point_types.keys()])\ndef ahu_points(row):\n    ahu_name = row.get(\'AHU\')\n    for cls, brickclass in point_types.items():\n        if cls in row:\n            point = row.get(cls)\n            G.add((BLDG[point], A, brickclass))\n            G.add((BLDG[point], BRICK.timeseries, [\n                (BRICK.hasTimeseriesId, Literal(row.get("uuid")))\n            ]))\n            G.add((BLDG[ahu_name], BRICK.hasPoint, BLDG[point]))\n```\n\n---\n\n`fixedpoint`: executes the rule if any new triples were added to the graph since it was last executed. This is helpful to avoid any dependency constraints between rules (e.g. making sure the floors exist so the biulding can be linked to them). The argument to the `fixedpoint` decorator is the string name of the graph object you are appending to (should be `G` in most cases)\n\nThe triples generated by this rule should be *consistent* so that RDFlib can effectively deduplicate. Generating a blank node with a random identifier can lead this rule to execute forever. Use with caution! This should always be the decorator immediately above the function definition.\n\n```python\n@tags("AHU")\n@fixedpoint("G")\ndef ahu_feeds(row):\n    ahu = row.get("AHU")\n    idnum = ahu[-1]\n    vavs = G.subjects(predicate=A, object=BRICK.VAV)\n    for vav in vavs:\n        label = list(G.objects(subject=vav, predicate=RDFS.label))[0]\n        if label.startswith(idnum):\n            G.add((BLDG[ahu], BRICK.feeds, vav))\n```\n\n## Driving\n\nThe stream of documents are done through a `Stream` object. A `Stream` object implements an optional `setup` method and a `next` method. A `CSVFileStream` and `JSONFileStream` implementation are provided. Some files (e.g. `examples/smc/smc.py` will define their own extensions to these streams to handle tasks like column renaming, data cleaning and transformations.\n\nCall the `drive` function on 1 or more `Stream` objects to create the graph (by default, stored in a global `G`  variable), then optionally validate (`G.validate()`) and serialize.\n',
    'author': 'Gabe Fierro',
    'author_email': 'gtfierro@mines.edu',
    'maintainer': None,
    'maintainer_email': None,
    'url': None,
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.7,<4.0',
}


setup(**setup_kwargs)
