Re: Casting from strings and/or inferring datatypes?

You could try
$ cat /tmp/test.n3
@prefix string: <http://www.w3.org/2000/10/swap/string#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix ex: <https://example.org/> .

ex:a ex:date "2021-09" .

{
  ?x ex:date ?d.
  (?d "^\\d{4}-(\\d{2})$") string:scrape ?m.
  (?m xsd:gMonth) log:dtlit ?y.
} => {
  ?x ex:month ?y
}.

$ cwm /tmp/test.n3 --think
#Processed by Id
        #    using base file:///tmp/test.n3
             @prefix : <#> .
    @prefix ex: <https://example.org/> .
    @prefix log: <http://www.w3.org/2000/10/swap/log#> .
    @prefix string: <http://www.w3.org/2000/10/swap/string#> .
    @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

     @forAll :d,
                :m,
                :x,
                :y .

    ex:a     ex:date "2021-09";
         ex:month "09"^^xsd:gMonth .
    {

          ( :d
            "^\\d{4}-(\\d{2})$" )
             string:scrape :m .
          ( :m
            xsd:gMonth )
             log:dtlit :y .
        :x     ex:date :d .

        }     => {:x     ex:month :y .
        } .

$ eye --nope /tmp/test.n3 --pass
eye --nope /tmp/test.n3 --pass
EYE v21.0902.2237 josd
SWI-Prolog version 8.3.29-5-g637e91ade
starting 31 [msec cputime] 29 [msec walltime]
#Processed by EYE v21.0902.2237 josd
#eye --nope /tmp/test.n3 --pass

GET file:///tmp/test.n3 SC=2
networking 2 [msec cputime] 2 [msec walltime]
PREFIX string: <http://www.w3.org/2000/10/swap/string#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
PREFIX ex: <https://example.org/>

ex:a ex:date "2021-09".
ex:a ex:month "09"^^xsd:gMonth.

reasoning 1 [msec cputime] 0 [msec walltime]
#2021-09-05T00:07:17.134Z in=2 out=2 ent=1 step=2 brake=2 inf=19393
sec=0.034 inf/sec=570382
#ENDS

2021-09-05T00:07:17.134Z in=2 out=2 ent=1 step=2 brake=2 inf=19393
sec=0.034 inf/sec=570382

-- https://josd.github.io


On Sun, Sep 5, 2021 at 1:25 AM Shaw, Ryan <ryanshaw@unc.edu> wrote:

> Suppose I have the following:
>
> ```
> @prefix string: <http://www.w3.org/2000/10/swap/string#> .
> @prefix ex: <https://example.org/> .
>
> ex:a ex:date "2021-09" .
>
> {
>   ?x ex:date ?d
>   . (?d "^\\d{4}-(\\d{2})$") string:scrape ?m
> } => {
>   ?x ex:month ?m
> }
> .
> ```
>
> Running this through a reasoner gives me:
>
> ```
> @prefix ex: <https://example.org/> .
>
> ex:a ex:month "09" .
>
> ```
>
> But supposed instead I wanted:
>
> ```
> @prefix ex: <https://example.org/> .
>
> ex:a ex:month 9 .
>
> ```
>
> or:
>
> ```
> @prefix ex: <https://example.org/> .
> @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
>
> ex:a ex:month “--09”^^xsd:gMonth .
>
> ```
>
> Is this possible?
>
> Specifically, are there builtins or other mechanisms for casting a string
> to another datatype?
>
>
>
>

Received on Sunday, 5 September 2021 00:10:03 UTC