Extending an enumeration

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Extending an enumeration

Florent Georges-3
  Hi,

  I struggle with a simple problem.  I have two simple types,
both are enumerations, one is a subset of the other.  Lets' say:

    working-days:
      - monday, tuesday, wednesday, thursday, friday
    week-days:
      - { working-days }, saturday, sunday

  I would like to have "week-days" defined as an extension of
"working-days".  Sounds sensible, doesn't it?  But I cannot find
how to do it...

  Any idea?

  Regards,

--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/

Reply | Threaded
Open this post in threaded view
|

Re: Extending an enumeration

Michael Kay

The only way to "extend" the value space of a simple type is by defining
a union type. You can define week-days as a union type with working-days
and (sat sun) as its member types.

Unfortunately XSLT/XQuery support for union types in 2.0/1.0 is very
weak: you won't be able to define functions that expect the union type,
for example. This changes in 3.0.

Michael Kay
Saxonica

On 25/07/2012 11:02, Florent Georges wrote:

>    Hi,
>
>    I struggle with a simple problem.  I have two simple types,
> both are enumerations, one is a subset of the other.  Lets' say:
>
>      working-days:
>        - monday, tuesday, wednesday, thursday, friday
>      week-days:
>        - { working-days }, saturday, sunday
>
>    I would like to have "week-days" defined as an extension of
> "working-days".  Sounds sensible, doesn't it?  But I cannot find
> how to do it...
>
>    Any idea?
>
>    Regards,
>


Reply | Threaded
Open this post in threaded view
|

Re: Extending an enumeration

C. M. Sperberg-McQueen-2
In reply to this post by Florent Georges-3

On Jul 25, 2012, at 4:02 AM, Florent Georges wrote:

>   Hi,
>
>   I struggle with a simple problem.  I have two simple types,
> both are enumerations, one is a subset of the other.  Lets' say:
>
>     working-days:
>       - monday, tuesday, wednesday, thursday, friday
>     week-days:
>       - { working-days }, saturday, sunday
>
>   I would like to have "week-days" defined as an extension of
> "working-days".  Sounds sensible, doesn't it?  But I cannot find
> how to do it...
>
>   Any idea?

Ideally, a schema language should distinguish carefully between
two relationships that can hold between two types:

  - The subset/superset relation holds when every
    value of T1 is a value of T2.

  - The subsumption relation holds when every value of
    T1 is subsumed by T2 -- where the precise nature of
    the 'subsumes' relation must be carefully defined, but
    informally means that one type provides "all the information"
    provided by the other type, and a bit more.

In XSD, the 'restriction' operation defines a subset relation
between two types, but there is no operation to define a
superset relation.  The 'extension' operation defines a
subsumption relation (the base type subsumes the
extended type) but there is no way to define the inverse
relation.  Lack of orthogonality often results from a failure
of design work to identify clear and useful primitive notions.

As Michael Kay observes, you can define week-days as a
union of working-days and {saturday, sunday}, but the
relation between the union type and the working-days type
is not one that XSD-aware processors or languages can
do much with. (In particular, unions which have T1 as a
member are not accepted as extensions of T1.)

So on the level of theoretical purity and conceptual beauty,
you're hosed.

On the practical level, whether you're hosed or not depends
on what exactly you want to do.  Why do you want
week-days as an extension of working-days, and not
working-days as a restriction of week-days?  What operations
are you trying to support or optimize?


--
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com 
* http://cmsmcq.com/mib                 
* http://balisage.net
****************************************************************





Reply | Threaded
Open this post in threaded view
|

Re: Extending an enumeration

Mukul Gandhi
In reply to this post by Florent Georges-3
Hi Florent,
    Related to this use-case, here's a different way of thinking about
XSD type inheritance in XSD 1.1 world.

<xs:complexType name="working-days">
    <xs:simpleContent>
         <xs:extension base="week-days">
             <xs:assert test="not($value = ('saturday', 'sunday'))"/>
         </xs:extension>
    </xs:simpleContent>
</xs:complexType>
       
       
<xs:simpleType name="week-days">
      <xs:restriction base="xs:string">
           <xs:enumeration value="monday"/>
           <xs:enumeration value="tuesday"/>
           <xs:enumeration value="wednesday"/>
           <xs:enumeration value="thursday"/>
           <xs:enumeration value="friday"/>
           <xs:enumeration value="saturday"/>
           <xs:enumeration value="sunday"/>
      </xs:restriction>
</xs:simpleType>

These set of XSD types, doesn't exactly model XSD components as per
your modeling recommendations (i.e, a simpleType should extend another
simpleType). But this allows us, to reuse the specification of value
space of one XSD type ("week-days") within another type definition
("working-days"). In this example, the derived type is using an
<assert> to constrain the value space of the base type.

Does this look somewhat ok?

On Wed, Jul 25, 2012 at 11:02 AM, Florent Georges <[hidden email]> wrote:

>   Hi,
>
>   I struggle with a simple problem.  I have two simple types,
> both are enumerations, one is a subset of the other.  Lets' say:
>
>     working-days:
>       - monday, tuesday, wednesday, thursday, friday
>     week-days:
>       - { working-days }, saturday, sunday
>
>   I would like to have "week-days" defined as an extension of
> "working-days".  Sounds sensible, doesn't it?  But I cannot find
> how to do it...
>
>   Any idea?
>
>   Regards,
>
> --
> Florent Georges
> http://fgeorges.org/
> http://h2oconsulting.be/
>



--
Regards,
Mukul Gandhi