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

Prolog initialisation failed #54

Open
lmichel opened this issue Jan 3, 2017 · 11 comments
Open

Prolog initialisation failed #54

lmichel opened this issue Jan 3, 2017 · 11 comments

Comments

@lmichel
Copy link

lmichel commented Jan 3, 2017

I'm sorry to reopen an issue which is rather likely a user support request (I'm an absolute beginner with Prolog). I guess that some other users can have to face the same problem.

I properly setup my swipl with Aptitude and swivm as suggested in thread #53

michel@obs-he-lm:~$ swipl --version
SWI-Prolog  version 7.2.3 for x86_64-linux
michel@obs-he-lm:~$ swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
Copyright (c) 1990-2015 ....
?- use_module(library(sgml)).
true.
?- use_module(library(chr)).
true.

When I try to process a schema, I get nothing on stdout; then I switch to the trace mode and I get the following output (truncated).

michel@obs-he-lm:~$ xsd2json -t purchaseorder.xsd
CHR:   (0) Insert: node_attribute(/home/michel/purchaseorder.xsd,[0],xmlns:xsd,http://www.w3.org/2001/XMLSchema,source) # <0>
....
....
CHR:   (1) Redo: node_attribute(/home/michel/purchaseorder.xsd,[0],xmlns:xsd,http://www.w3.org/2001/XMLSchema,source) # <0>
CHR:   (0) Fail: node_attribute(/home/michel/purchaseorder.xsd,[0],xmlns:xsd,http://www.w3.org/2001/XMLSchema,source) # <0>
ERROR: Prolog initialisation failed:
ERROR: Domain error: `chr_port' expected, found `none'

I've no idea at all (and Google either) about that chr_port.
Is there some missing parameter or resource?

LM

@fnogatz
Copy link
Owner

fnogatz commented Jan 3, 2017

Could you please link to the used purchaseorder.xsd file or send it to (deleted), so I can have a look at it?

@lmichel
Copy link
Author

lmichel commented Jan 3, 2017

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:annotation>
    <xsd:documentation xml:lang="en">
     Purchase order schema for Example.com.
     Copyright 2000 Example.com. All rights reserved.
    </xsd:documentation>
  </xsd:annotation>

  <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>

  <xsd:element name="comment" type="xsd:string"/>

  <xsd:complexType name="PurchaseOrderType">
    <xsd:sequence>
      <xsd:element name="shipTo" type="USAddress"/>
      <xsd:element name="billTo" type="USAddress"/>
      <xsd:element ref="comment" minOccurs="0"/>
      <xsd:element name="items"  type="Items"/>
    </xsd:sequence>
    <xsd:attribute name="orderDate" type="xsd:date"/>
  </xsd:complexType>

  <xsd:complexType name="USAddress">
    <xsd:sequence>
      <xsd:element name="name"   type="xsd:string"/>
      <xsd:element name="street" type="xsd:string"/>
      <xsd:element name="city"   type="xsd:string"/>
      <xsd:element name="state"  type="xsd:string"/>
      <xsd:element name="zip"    type="xsd:decimal"/>
    </xsd:sequence>
    <xsd:attribute name="country" type="xsd:NMTOKEN"
                   fixed="US"/>
  </xsd:complexType>

  <xsd:complexType name="Items">
    <xsd:sequence>
      <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="productName" type="xsd:string"/>
            <xsd:element name="quantity">
              <xsd:simpleType>
                <xsd:restriction base="xsd:positiveInteger">
                  <xsd:maxExclusive value="100"/>
                </xsd:restriction>
              </xsd:simpleType>
            </xsd:element>
            <xsd:element name="USPrice"  type="xsd:decimal"/>
            <xsd:element ref="comment"   minOccurs="0"/>
            <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
          </xsd:sequence>
          <xsd:attribute name="partNum" type="SKU" use="required"/>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>

  <!-- Stock Keeping Unit, a code for identifying products -->
  <xsd:simpleType name="SKU">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{3}-[A-Z]{2}"/>
    </xsd:restriction>
  </xsd:simpleType>

</xsd:schema>

@fnogatz
Copy link
Owner

fnogatz commented Jan 3, 2017

The bug happened because of types starting with capital letters, in this case XSD's built-in NMTOKEN, which was handled incorrectly and therefore recognized as a Prolog variable. I added three new tests and a fix, so the given purchaseorder.xsd example results in a valid JSON Schema representation.
Unfortunately I have to take a further look at the other example file you sent me via mail as it still fails.

@fnogatz
Copy link
Owner

fnogatz commented Jan 3, 2017

This is... strange. Unfortunately SWI-Prolog is not good at versioning (semver would be too easy, right?), but according to my information split_string/4 should be part of SWI-Prolog 7. I even tried with a local installation of v7.2.3 like you are using. Could you please open a SWI-Prolog REPL (simply call swipl from command line) and run the following query:

split_string('a:B',':','', L).

Does this work? What's the output?

edit: Replaced split_string/4 by atomic_list_concat/3 again for SWI6 portability.

@lmichel
Copy link
Author

lmichel commented Jan 3, 2017

Sorry, I ran a wrong swipl version (6.xx). The problem is that the installed xsd2json does not take into account the swivm predicat (use 7.2). That seems to work from the git clone:

michel@obs-he-lm:~/gitRepositories/xsd2json$ which swipl
/home/michel/.swivm/versions/7.2.3/bin/swipl

But that fails from the CLI.
If I, look at the xsd2json trace, I can see that the native install of swipl is invoked instead of the cloned one

michel@obs-he-lm:~/gitRepositories/xsd2json$ which swipl
/home/michel/.swivm/versions/7.2.3/bin/swipl
michel@obs-he-lm:~/gitRepositories/xsd2json$ strace -f xsd2json -t purchaseorder.xsd 2>&1 | grep swipl 
execve("/usr/lib/swi-prolog/bin/amd64/swipl", ["/usr/lib/swi-prolog/bin/amd64/sw"..., "-x", "/usr/bin/xsd2json", "--", "-t", "purch
aseorder.xsd"], [/* 70 vars */]) = 0
....

This is a shell issue.

@fnogatz
Copy link
Owner

fnogatz commented Jan 3, 2017

Nice catch! I am not sure why the wrong swipl executable is used. Nevertheless I checked the Prolog predicates specific for SWI-Prolog 7 and replaced them by predicates which work in both versions. So xsd2json is compatible to SWI-Prolog 6 again (v1.7.14@npm).
But this does yet not solve the problem for your second test file :)

@lmichel
Copy link
Author

lmichel commented Jan 3, 2017 via email

@fnogatz
Copy link
Owner

fnogatz commented Jan 3, 2017

Okay, had to rewrite quite some code but it is working now, even for your VOTable.xsd test file (just be patient - the translation takes about 12 seconds on my machine). The only thing that's missing is the conversion of the following type:

<xs:complexType name="anyTEXT" mixed="true">
  <xs:sequence>
    <xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
  </xs:sequence>
</xs:complexType>

I'm not sure this is the best way to specify an element that contains HTML in XML Schema. What would you expect to be a valid JSON Schema translation?

@fnogatz
Copy link
Owner

fnogatz commented Jan 3, 2017

The updated version is available as 1.8.0 on npm.

@lmichel
Copy link
Author

lmichel commented Jan 4, 2017 via email

@lmichel
Copy link
Author

lmichel commented Jan 4, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants