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

Reasoner loading error under Ubuntu - BOM and CR/LF problem #36

Closed
apohllo opened this issue Jan 3, 2022 · 2 comments
Closed

Reasoner loading error under Ubuntu - BOM and CR/LF problem #36

apohllo opened this issue Jan 3, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@apohllo
Copy link

apohllo commented Jan 3, 2022

I tried the examples in a cognipy installation under Ubuntu. At first it seemed that everything works as expected, but suddenly I started to receive the following error:

Traceback (most recent call last):
  File "check_consistency.py", line 28, in <module>
    printReasoningInfo(onto)
  File "check_consistency.py", line 15, in printReasoningInfo
    info=onto.reasoningInfo()
  File "/usr/local/lib/python3.7/dist-packages/cognipy/ontology.py", line 299, in reasoningInfo
    self.super_concepts_of("a thing")
  File "/usr/local/lib/python3.7/dist-packages/cognipy/ontology.py", line 179, in super_concepts_of
    return cognipy_call(self._uid, "GetSuperConceptsOf", cnl, direct)
  File "/usr/local/lib/python3.7/dist-packages/cognipy/interop.py", line 71, in cognipy_call
    raise translate_exception(json.loads(js))
Exception: [

  "InvalidOperationException",
  {
    "ClassName": "System.InvalidOperationException",
    "Message": "The reasoner is not initialized. You need to call Load... before calling this method.",
    "Data": null,
    "InnerException": null,

    "HelpURL": null,

    "StackTraceString": "  at CogniPy.CogniPySvr.get_reasoner () [0x00008] in <f8783c48f78341ba843524fd57b41eb3>:0 \n  at CogniPy.CogniPySvr.Materialize () [0x0001b] in <f8783c48f78341ba843524fd57b41eb3>:0 \n  at CogniPy.CogniPySvr.GetSuperConceptsOf (System.String cnlName, System.Boolean direct) [0x00000] in <f8783c48f78341ba843524fd57b41eb3>:0 \n  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)\n  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <533173d24dae460899d2b10975534bb0>:0 ",
    "RemoteStackTraceString": null,
    "RemoteStackIndex": 0,
    "ExceptionMethod": null,
    "HResult": -2146233079,
    "Source": "CogniPyLib"
  }
]

My python version is 3.7.12 and mono version is 6.12.0.122.
I will submit a Dockerfile which will allow to reproduce the error.

Update:
example.tar.gz

@apohllo
Copy link
Author

apohllo commented Jan 10, 2022

The reason was a problem with the file, not with the tool itself. Two files were created in Fluent editor under Windows.
There were two issues related to these files:

  • the files include BOM
  • the files had cr/lf line ending

I've used the example from the tutorial to concatenate the files. I.e. it reads the files and joins them with newlines. Yet, since there were these extra bytes, the final string included a mixed set of newlines and extra BOM inside the string.
Removing the BOMS and changing cr/lf into lf fixed the issue.

Yet I think it would be better that if:

  • the tool took care of cr/lf vs lf issue
  • the tutorial mentioned the problem with BOM if the files are created in fluent editor
  • the error was more informative

@apohllo apohllo changed the title Reasoner loading error under Ubuntu Reasoner loading error under Ubuntu - BOM and CR/LF problem Jan 10, 2022
@kcieslinski kcieslinski added the bug Something isn't working label Jan 27, 2022
kaplan196883 added a commit that referenced this issue Jan 31, 2022
@kaplan196883
Copy link
Contributor

The bug was caused by incorrect encoding passed to the open function. Fluent Editor is using 'utf-8-sig' encoding and it needs to be used when opening these files:
'''onto=Ontology("cnl/string",'\n'.join(open(fn,"rt",encoding='utf-8-sig').read() for fn in ["data/sample-data.encnl"]))'''

The informative exception was disable by another bug that was also fixed. Now the error message looks like that:

---------------------------------------------------------------------------
ParseException                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_19720/4239347022.py in <module>
----> 1 onto=Ontology("cnl/string",'\n'.join(open(fn,"rt").read() for fn in ["data/sample-data.encnl"]))

D:\ROOT\cognipy\docsrc\jupyter_notebooks\Bugreports\cognipy\ontology.py in __init__(self, source, arg, verbose, evaluator, graph_attribute_formatter, stop_on_error)
    104                          modalCheck, passParamsAsCnl, stop_on_error)
    105         elif source == "cnl/string":
--> 106             cognipy_call(self._uid, "LoadCnlFromString", arg,
    107                          loadAnnotations, modalCheck, passParamsAsCnl, stop_on_error)
    108         elif source == "rdf/uri":

D:\ROOT\cognipy\docsrc\jupyter_notebooks\Bugreports\cognipy\interop.py in cognipy_call(uid, cmd, *args)
     72     js="\r\n".join(ja)
     73     if fl.strip()=='@exception':
---> 74         raise translate_exception(json.loads(js))
     75     return json.loads(js)
     76 

ParseException: {'Errors': [{'Line': 0, 'Column': 41, 'Pos': 41, 'Context': 'Comment: Sample data to test assertions.\n\nSpan-1 is a last-name.\nSpan-2 is a first-name.\nSpan-2 connects-with Span-1.\n\nSpan-3 is a last-name.\nSpan-4 is a first-name.\nSpan-3 connects-with Span-4.\n\n\n\n\n', 'Hint': 'Comment: Sample data to test assertions^.\n\nSpan-1 is a last-name.\nSpan-2 is a first-name.\nSpan-2 connects-with Span-1.\n\nSpan-3 is a last-na'}]}

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