# dafact
Encodes data as ASP facts.
```dafact``` solves the reiterative task of encoding a dataset into a set of Answer Set Programming facts. The resulting ASP program, which can be partially personalized, can be encoded as [python clingo](https://github.com/potassco/clingo) objects directly or as plain text, and it handles floating point numbers automatically.
Data can be fed into ```dafact``` through CSV files, [numpy](https://github.com/numpy/numpy) arrays, [pandas](https://github.com/pandas-dev/pandas) DataFrames and other typical formats.
It can be used both as a python library and as a command line tool.
# Installation
The tool is easily installable through ```pip```:
```
python3 -m pip install dafact
```
## Short usage
[A more detailed usage guide can be found here](examples/README.md).
### Python
```Dafacter``` python class provides all the funcionality. Once fed with data, a ```Dafacter``` object provides two main methods for obtaining a logic program:
```python
from dafact import Dafacter
dafacter = Dafacter("data/haberman.csv", have_names=True) # Fed data into the object
clingo_facts = dafacter.as_clingo_facts() # Returns a list of clingo.Function objects
program_text = dafacter.as_program_string() # Returns the program as plain text
```
The following piece of code loads the [haberman](https://www.kaggle.com/gilsousa/habermans-survival-data-set) dataset from a csv file and encodes it as a logic program.
```python
# examples/usage_csv.py
from dafact import Dafacter
dafacter = Dafacter("data/haberman.csv", have_names=True)
print(dafacter.as_program_string())
```
The result of that code would be:
```
feature("age"). feature("op_year"). feature("nodes"). feature("survival").
instance(0). value(0,"age",30). value(0,"op_year",64). value(0,"nodes",1). value(0,"survival",1).
instance(1). value(1,"age",30). value(1,"op_year",62). value(1,"nodes",3). value(1,"survival",1).
(. . .)
```
The encoded style can also be tweaked easily, and it accepts different kind of data sources from [numpy](https://github.com/numpy/numpy) arrays to [pandas](https://github.com/pandas-dev/pandas) DataFrames. A more detailed guide on usage of the python library can be found in [examples folder](examples/README.md).
### Command line tool
Once installed through ```pip``` users can use ```dafact``` for directly obtain a logic program from csv files through the use of the **command line tool**. The usage of the tool is the same to the use of the ```Dafacter``` python class for csv files.
```
~/$ dafact --help
usage: dafact [-h] [--feature-names [FEATURE_NAMES [FEATURE_NAMES ...]]] [--factor FACTOR]
[--numerical-columns [NUMERICAL_COLUMNS [NUMERICAL_COLUMNS ...]]] [--have-names] [--omit-names] [--delimiter DELIMITER]
infile outfile
Dafact CLI Encodes data as ASP facts.
positional arguments:
infile Input csv file.
outfile Ouput ASP program.
optional arguments:
-h, --help show this help message and exit
Options:
--feature-names [FEATURE_NAMES [FEATURE_NAMES ...]]
Feature names for the csv columns.
--factor FACTOR factor help
--numerical-columns [NUMERICAL_COLUMNS [NUMERICAL_COLUMNS ...]]
Indexes for numerical columns.
--have-names Must be if csv have the name of the columns in the first line.
--omit-names Used together with --have-names for omitting the names in the file.
--delimiter DELIMITER
Field delimiter for the csv file.
```
Raw data
{
"_id": null,
"home_page": "https://github.com/bramucas/dafact",
"name": "dafact",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6.0",
"maintainer_email": "",
"keywords": "logic programming,answer set programming",
"author": "Brais Mu\u00f1iz",
"author_email": "mc.brais@gmail.com",
"download_url": "",
"platform": null,
"description": "# dafact\nEncodes data as ASP facts.\n\n```dafact``` solves the reiterative task of encoding a dataset into a set of Answer Set Programming facts. The resulting ASP program, which can be partially personalized, can be encoded as [python clingo](https://github.com/potassco/clingo) objects directly or as plain text, and it handles floating point numbers automatically.\n\nData can be fed into ```dafact``` through CSV files, [numpy](https://github.com/numpy/numpy) arrays, [pandas](https://github.com/pandas-dev/pandas) DataFrames and other typical formats.\n\nIt can be used both as a python library and as a command line tool.\n\n# Installation\nThe tool is easily installable through ```pip```:\n```\npython3 -m pip install dafact\n```\n\n## Short usage\n\n[A more detailed usage guide can be found here](examples/README.md).\n\n### Python\n```Dafacter``` python class provides all the funcionality. Once fed with data, a ```Dafacter``` object provides two main methods for obtaining a logic program:\n```python\nfrom dafact import Dafacter\ndafacter = Dafacter(\"data/haberman.csv\", have_names=True) # Fed data into the object\nclingo_facts = dafacter.as_clingo_facts() # Returns a list of clingo.Function objects\nprogram_text = dafacter.as_program_string() # Returns the program as plain text\n```\n\nThe following piece of code loads the [haberman](https://www.kaggle.com/gilsousa/habermans-survival-data-set) dataset from a csv file and encodes it as a logic program.\n```python\n# examples/usage_csv.py\nfrom dafact import Dafacter\n\ndafacter = Dafacter(\"data/haberman.csv\", have_names=True)\nprint(dafacter.as_program_string())\n```\n\nThe result of that code would be:\n\n```\nfeature(\"age\"). feature(\"op_year\"). feature(\"nodes\"). feature(\"survival\").\ninstance(0). value(0,\"age\",30). value(0,\"op_year\",64). value(0,\"nodes\",1). value(0,\"survival\",1).\ninstance(1). value(1,\"age\",30). value(1,\"op_year\",62). value(1,\"nodes\",3). value(1,\"survival\",1).\n(. . .)\n```\n\nThe encoded style can also be tweaked easily, and it accepts different kind of data sources from [numpy](https://github.com/numpy/numpy) arrays to [pandas](https://github.com/pandas-dev/pandas) DataFrames. A more detailed guide on usage of the python library can be found in [examples folder](examples/README.md).\n\n### Command line tool\nOnce installed through ```pip``` users can use ```dafact``` for directly obtain a logic program from csv files through the use of the **command line tool**. The usage of the tool is the same to the use of the ```Dafacter``` python class for csv files.\n\n```\n~/$ dafact --help\nusage: dafact [-h] [--feature-names [FEATURE_NAMES [FEATURE_NAMES ...]]] [--factor FACTOR]\n [--numerical-columns [NUMERICAL_COLUMNS [NUMERICAL_COLUMNS ...]]] [--have-names] [--omit-names] [--delimiter DELIMITER]\n infile outfile\n\nDafact CLI Encodes data as ASP facts.\n\npositional arguments:\n infile Input csv file.\n outfile Ouput ASP program.\n\noptional arguments:\n -h, --help show this help message and exit\n\nOptions:\n --feature-names [FEATURE_NAMES [FEATURE_NAMES ...]]\n Feature names for the csv columns.\n --factor FACTOR factor help\n --numerical-columns [NUMERICAL_COLUMNS [NUMERICAL_COLUMNS ...]]\n Indexes for numerical columns.\n --have-names Must be if csv have the name of the columns in the first line.\n --omit-names Used together with --have-names for omitting the names in the file.\n --delimiter DELIMITER\n Field delimiter for the csv file.\n```\n\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Encodes data as ASP facts.",
"version": "0.5",
"project_urls": {
"Homepage": "https://github.com/bramucas/dafact"
},
"split_keywords": [
"logic programming",
"answer set programming"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "de652aba9d789694fabba3bc807c3b4b8500d7ab37bfe99e8af9d043b22a68bc",
"md5": "8f0caef751160a64d0585dea875d9966",
"sha256": "f3fe3ee6cc16c9882bcf30840dfe3724a13d34d49ec6245daf390600635e40ed"
},
"downloads": -1,
"filename": "dafact-0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8f0caef751160a64d0585dea875d9966",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.0",
"size": 8321,
"upload_time": "2023-09-15T09:30:57",
"upload_time_iso_8601": "2023-09-15T09:30:57.742081Z",
"url": "https://files.pythonhosted.org/packages/de/65/2aba9d789694fabba3bc807c3b4b8500d7ab37bfe99e8af9d043b22a68bc/dafact-0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-15 09:30:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bramucas",
"github_project": "dafact",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "dafact"
}