Delay in file creation with Python implementation in ASP
- 主要言語
- Python
- スター
- 37
- フォーク
- 8
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Hello,
I have an issue while using Clyngor to encapsulate ASP files (which also use python implementation). The python implementation in ASP is used to select some atoms in the answer and to write these atoms in a file. The ASP encoding and fact have been tested with Clingo (version 5.2.2 compiled with Python) and it works, the file is created.
Clyngor achieves to create the file but there is a delay in the creation of the file. Indeed the file is not accessible right after the solver call. If I try to use the file, I have an error saying that the file doesn't exist. But when the script ends, the file exists.
I write a simple example, with encoding and fact files (which are working with my Clingo) and a python script with Clyngor which creates the file but runs into an error when trying to access the file with the `print(file.read())`.
The ASP encoding extracts a number from a predicate with two numbers, assign it to another predicate and then write the new predicate in a file.
Example:
Python script:
```python
import clyngor
clyngor.solve(('test.lp', 'data.lp'))
print(open('resultfile.lp').read())
```
Encoding file:
```
#script (python)
import clingo
def on_model(answer, output_file):
atoms=answer.symbols(atoms=True)
for atom in atoms:
if atom.name == "count" and len(atom.arguments) == 1:
output_file.write( "count("+str(atom.arguments[0])+").\n")
def main(prg):
output_file = open("resultfile.lp", "w")
prg.ground([("base", [])])
for answer_number, answer in enumerate(prg.solve(yield_=True, async=True), start=1):
print(answer)
on_model(answer, output_file)
output_file.close()
#end.
count(X) :- query(X, A).
```
`data.lp`:
```
query(1,2).
query(2,3).
query(4,5).
```
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
評価
この issue はまだ評価されていません。