Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in String library: str2lst? #84

Closed
Mezzenilium opened this issue Apr 20, 2022 · 3 comments
Closed

bug in String library: str2lst? #84

Mezzenilium opened this issue Apr 20, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Mezzenilium
Copy link

I try to use the predicates of the String library of Problog2, but it does not work or I have not understood the way to properly use them :
%:- use_module(library(lists)).
:- use_module(library(string)).

  o1(L) :- L = str2lst("aaaa, zzzz, eeee, rrrr").
  o2(S) :- S = lst2str(["aaa","dddd","fffff"]).
  o3(T) :- T = join('',["aaa","dddd","fffff"]).
  
  query(o1(S)).
  query(o2(S)).
  query(o3(S)).

gives

  o1(str2lst("aaaa, zzzz, eeee, rrrr")):	1         
  o2(lst2str(["aaa", "dddd", "fffff"])):	1         
  o3(join('',["aaa", "dddd", "fffff"])):	1

Originally posted by @Mezzenilium in #79 (comment)

@Mezzenilium
Copy link
Author

I have made some progress in the use of the string library. I manage to have lst2str, join and concat working. But str2lst (test1) gives "An unexpected error has occurred." .

:- use_module(library(string)).
 
  atome1('aaaa zzzz eeee rrrr').
  test1(L) :- atome1(A), str2lst(A, L).
  
  atome2(['aaa','dddd','fffff']).
  test2(L) :- atome2(A), lst2str(A, L). 
  
  sep(',').
  atome3(['aaa','dddd','fffff']).
  test3(L) :- sep(S),atome3(A), join(S, A, L). 
  
  atome4(['aaa','dddd','fffff']).
  test4(L) :- atome3(A), concat(A, L). 
  
  %query(test1(V)).
  query(test2(U)).
  query(test3(T)).
  query(test4(X)).

@VincentDerk
Copy link
Collaborator

VincentDerk commented Apr 23, 2022

That might be a bug... @rmanhaeve What do you think?

:- use_module(library(string)).

test1(L) :- str2lst('aaaa zzzz eeee rrrr', L).
test2(L) :- lst2str(['aaa','dddd','fffff'], L).
test3(L) :- join(',', ['aaa','dddd','fffff'], L).
test4(L) :- concat(['aaa','dddd','fffff'], L).
  
query(test1(_)).
%query(test2(_)).
%query(test3(_)).
%query(test4(_)).

yields

  File ".../problog/problog/extern.py", line 110, in _convert_output
    return list2term(a)
  File ".../problog/problog/logic.py", line 119, in list2term
    for e in reversed(lst):
TypeError: 'map' object is not reversible

An unexpected error has occurred.

The current definition of str2lst (from string.py)

@problog_export("+str", "-list")
def str2lst(string):
    return map(Term, map(make_safe, string))

should probably be

@problog_export("+str", "-list")
def str2lst(string):
    return list(map(Term, map(make_safe, string)))

(notice return function), because right now it returns a map-function rather than a list. And since it expects to get a list ("-list"), it tries to convert the python list into a prolog list (here) which crashes because it instead received a map-function that is not reversible.

@VincentDerk VincentDerk changed the title I try to use the predicates of the String library of Problog2, but it does not work or I have not understood the way to properly use them : bug in String library: str2lst? Apr 23, 2022
@VincentDerk VincentDerk added the bug Something isn't working label Apr 23, 2022
@Mezzenilium
Copy link
Author

I have modified the string.py file with the statement return list(map(Term, map(make_safe, string))).
My test examples run smoothly now and str2lst transforms a string in a list of its characters.

Thank you for your support.

VincentDerk added a commit that referenced this issue Jun 29, 2022
Mainly bugfixes, but we also changed the Term's hashing method. If this proofs to be worse, we may reconsider switching back later.

* Bugfix library/string.py::str2lst (public issue #84)
* Bugfix return exit code instead of result - only for probability task atm (public issue #82)
* Critical Bugfix in dSharp library (compiled CNF theory with too long clauses could yield wrong result)
* Bugfix in pypl related to lists (private issue #16)
* Minor improvements to LFI
* Changed Term's hashing method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants