Git Product home page Git Product logo

cognitum-octopus / cognipy Goto Github PK

View Code? Open in Web Editor NEW
46.0 10.0 10.0 136.08 MB

In-memory Graph Database and Knowledge Graph with Natural Language Interface, compatible with Pandas

Home Page: https://cognitum-octopus.github.io/cognipy/

License: Other

C# 36.03% Batchfile 0.04% Python 0.56% JavaScript 0.12% Prolog 35.54% Smarty 0.15% Makefile 0.01% CSS 0.01% Jupyter Notebook 27.42% Smalltalk 0.14%
owl jena rl-reasoner rdf graph-algorithms pandas python elk controlled-natural-language natural-language-interface graph memory-graph-database knowledge-graph sparql dataframe jupyter

cognipy's Issues

FluentEditor is using encoding='utf-8-sig'

Fluent Editor is using 'utf-8-sig' encoding and it needs to be used when opening these files e.g.:
'''onto=Ontology("cnl/string",'\n'.join(open(fn,"rt",encoding='utf-8-sig').read() for fn in ["data/sample-data.encnl"]))'''
Please update documentation and examples

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

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

Misleading error message

Providing path to non-existing encnl file the error is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "venv/lib/python3.6/site-packages/cognipy/ontology.py", line 104, in __init__
    modalCheck, passParamsAsCnl, stop_on_error)
  File "venv/lib/python3.6/site-packages/cognipy/interop.py", line 71, in cognipy_call
    raise translate_exception(json.loads(js))
Exception: [

  "IllegalArgumentException",

  {

    "ClassName": "java.lang.IllegalArgumentException",

    "Message": "URI is not absolute",

    "Data": null,

    "InnerException": null,

    "HelpURL": null,

    "StackTraceString": "  at CogniPy.CogniPySvr.Load (CogniPy.ReferenceManager+WhatToLoad whatToLoad, System.String contentToLoad, CogniPy.CNL.DL.Paragraph impliAst, System.Boolean throwOnException, System.Boolean loadAnns, System.Boolean materialize, System.Boolean modalChecker) [0x00057] in <f8783c48f78341ba843524fd57b41eb3>:0 \n  at CogniPy.CogniPySvr.LoadCnl (System.String filename, CogniPy.CNL.DL.Paragraph impliAst, System.Boolean throwOnException, System.Boolean loadAnns, System.Boolean materialize, System.Boolean modalChecker) [0x00000] in <f8783c48f78341ba843524fd57b41eb3>:0 \n  at CogniPy.CogniPySvr.LoadCnl (System.String filename, System.Boolean loadAnnotations, System.Boolean materialize, System.Boolean modalChecker, System.Boolean throwOnError) [0x00000] in <f8783c48f78341ba843524fd57b41eb3>:0 \n  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)\n  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <8f2c484307284b51944a1a13a14c0266>:0 ",

    "RemoteStackTraceString": null,

    "RemoteStackIndex": 0,

    "ExceptionMethod": null,

    "HResult": -2146233088,

    "Source": "CogniPyLib",

    "$0": {

      "$0": {

        "type": "java.lang.IllegalArgumentException, IKVM.OpenJDK.Core, Version=8.1.5717.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58",

        "sig": null

      },

      "$1": {

        "$0": {

          "type": "java.lang.RuntimeException, IKVM.OpenJDK.Core, Version=8.1.5717.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58",

          "sig": null

        },

        "$1": {

          "$0": {

            "type": "java.lang.Exception, IKVM.OpenJDK.Core, Version=8.1.5717.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58",

            "sig": null

          },

          "$1": {

            "$0": {

              "type": "java.lang.Throwable, IKVM.OpenJDK.Core, Version=8.1.5717.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58",

              "sig": null

            },

            "$1": "Ljava/lang/Throwable;",

            "$2": "Ljava/lang/String;",

            "$3": "[Ljava/lang/StackTraceElement;",

            "$4": "Ljava/util/List;",

            "$5": null,

            "$data": "FAFyASgAE2phdmEubGFuZy5UaHJvd2FibGXVxjUnOXe4ywMABEwABWNhdXNlARBMAA1kZXRhaWxNZXNzYWdlAQ1bAApzdGFja1RyYWNlARdMABRzdXBwcmVzc2VkRXhjZXB0aW9ucwIA"

          },

          "$data": "FAFyASAAE2phdmEubGFuZy5FeGNlcHRpb27Q/R8+GjscxAIAAAEA"

        },

        "$data": "FAFyAScAGmphdmEubGFuZy5SdW50aW1lRXhjZXB0aW9unl8GRwo0g+UCAAABAA=="

      },

      "$data": "FAFyAS8AImphdmEubGFuZy5JbGxlZ2FsQXJndW1lbnRFeGNlcHRpb261iXPTfWaPvAIAAAEA"

    },

    "$2": "URI is not absolute",

    "$3": [],

    "$4": [],

    "$data": "CgUA"

  }

]

To reproduce (on Ubuntu):

onto = Ontology("cnl/file","nonexisting.encnl")

ParseException for `K9s is something.`

Using

onto = Ontology("cnl/file","hello.encnl",stop_on_error=True)

Works with

%%writefile hello.encnl
Kas is something.

Errors with

%%writefile hello.encnl
K9s is something.
---------------------------------------------------------------------------
ParseException                            Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 onto = Ontology("cnl/file","hello.encnl",stop_on_error=True)

File /opt/conda/lib/python3.10/site-packages/cognipy/ontology.py:103, in Ontology.__init__(self, source, arg, verbose, evaluator, graph_attribute_formatter, stop_on_error)
    101 self._uid = cognipy_create()
    102 if source == "cnl/file":
--> 103     cognipy_call(self._uid, "LoadCnl", arg, loadAnnotations,
    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)

File /opt/conda/lib/python3.10/site-packages/cognipy/interop.py:76, in cognipy_call(uid, cmd, *args)
     74 js="\r\n".join(ja)
     75 if fl.strip()=='@exception':
---> 76     raise translate_exception(json.loads(js))
     77 return json.loads(js)

ParseException: {'Errors': [{'Line': 0, 'Column': 0, 'Pos': 0, 'Context': 'K9s is something.\n', 'Hint': 'K^9s is something.'}]}

(running in a jupyther/minimal image with mono added)

insert_cnl, delete_cnl methods output

image

Names of methods suggests that you can insert/delete any CNL yet if you insert/delete incorrect cnl like subsumption in attached pic error occures. Maybe output can be prettier?

Clean up CogniPySvr class

Analyze code in CogniPySvr class in terms of unused/untested methods since it's most exposed class to a user

serialization error

If X connects-to something that connects-to Y then Y follows X.
follows->followed

Problem with the disjointness assertion

It seems there's an error with the disjointness operator in CogniPy.

The following assertions result with an inconsistency detected in the ontology:

Anything either 
  is a second-name,
  is a first-name or
  is a last-name
  or-something-else.

First-Name-1 is a first-name.
First-Name-1 is a last-name.

While the following assertions does not:

Anything either 
  is a first-name or
  is a last-name
  or-something-else.

First-Name-1 is a first-name.
First-Name-1 is a last-name.

Union in range of the role

BTW there's a similar issue with assertions on relations.

Both these work:

No first-name is pesel-num.
Every first-name connects-with nothing-but thing that is a pesel-num.
First-Name-6 is a first-name.
First-Name-7 is a first-name.
First-Name-6 connects-with First-Name-7.
Causes error.

No first-name is last-name.
Every first-name connects-with nothing-but thing that is a last-name.
First-Name-6 is a first-name.
First-Name-7 is a first-name.
First-Name-6 connects-with First-Name-7.
Causes error too.

But:

No first-name is last-name.
No first-name is pesel-num.
Every first-name connects-with nothing-but thing that is a last-name and-or pesel-num.
First-Name-6 is a first-name.
First-Name-7 is a first-name.
First-Name-6 connects-with First-Name-7.
Does not cause an error.

@apohllo

Author
apohllo commented 4 days ago
The RDF/OWL conversions are as follows, for the first type of assertion:

<rdfs:subClassOf>
  <owl:Restriction>
    <owl:onProperty rdf:resource="http://www.cognitum.eu/onto#connectsWith" />
    <owl:allValuesFrom rdf:resource="http://www.cognitum.eu/onto#lastName" />
  </owl:Restriction>
</rdfs:subClassOf>

and for the second type:

<rdfs:subClassOf>
  <owl:Restriction>
    <owl:onProperty rdf:resource="http://www.cognitum.eu/onto#connectsWith" />
    <owl:allValuesFrom>
      <owl:Class>
        <owl:unionOf rdf:parseType="Collection">
          <rdf:Description rdf:about="http://www.cognitum.eu/onto#lastName" />
          <rdf:Description rdf:about="http://www.cognitum.eu/onto#peselNum" />
        </owl:unionOf>
      </owl:Class>
    </owl:allValuesFrom>
  </owl:Restriction>
</rdfs:subClassOf>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.