-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Option to explicitly create SimpleType classes #692
Comments
This will be tricky to implement, throughtout the process there is a naive approach of keep what it's really needed discard or flatten everything else. I wouldn't discard any contribution on this one, based on some sort of config of course. |
closing this one |
Hello @tefra, is it possible to reopen this one ? I am very interested to have simpleTypes as types. More precisely I have simpleTypes that I want to transform as numpy or specific python types. For example, an excerpt of my schema: <?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation xml:lang="en">GEOSX Input Schema</xsd:documentation>
</xsd:annotation>
<xsd:simpleType name="R1Tensor">
<xsd:restriction base="xsd:string">
<xsd:pattern value=".*[\[\]`$].*|\s*\{\s*([+-]?[\d]*([\d]\.?|\.[\d])[\d]*([eE][-+]?[\d]+|\s*)\s*,\s*){2}[+-]?[\d]*([\d]\.?|\.[\d])[\d]*([eE][-+]?[\d]+|\s*)\s*\}\s*" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="R1Tensor32">
<xsd:restriction base="xsd:string">
<xsd:pattern value=".*[\[\]`$].*|\s*\{\s*([+-]?[\d]*([\d]\.?|\.[\d])[\d]*([eE][-+]?[\d]+|\s*)\s*,\s*){2}[+-]?[\d]*([\d]\.?|\.[\d])[\d]*([eE][-+]?[\d]+|\s*)\s*\}\s*" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="R2SymTensor">
<xsd:restriction base="xsd:string">
<xsd:pattern value=".*[\[\]`$].*|\s*\{\s*([+-]?[\d]*([\d]\.?|\.[\d])[\d]*([eE][-+]?[\d]+|\s*)\s*,\s*){5}[+-]?[\d]*([\d]\.?|\.[\d])[\d]*([eE][-+]?[\d]+|\s*)\s*\}\s*" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="geos_dataRepository_PlotLevel">
<xsd:restriction base="xsd:string">
<xsd:pattern value=".*[\[\]`$].*|[+-]?[\d]+" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="globalIndex">
<xsd:restriction base="xsd:string">
<xsd:pattern value=".*[\[\]`$].*|[+-]?[\d]+" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="globalIndex_array">
<xsd:restriction base="xsd:string">
<xsd:pattern value=".*[\[\]`$].*|\s*\{\s*(([+-]?[\d]+\s*,\s*)*[+-]?[\d]+\s*)?\}\s*" />
</xsd:restriction>
</xsd:simpleType>
....
<xsd:complexType name="ConstantPermeabilityType">
<!--permeabilityComponents => xx, yy and zz components of a diagonal permeability tensor.-->
<xsd:attribute name="permeabilityComponents" type="R1Tensor" use="required" />
<!--name => A name is required for any non-unique nodes-->
<xsd:attribute name="name" type="groupName" use="required" />
</xsd:complexType>
....
<xsd:complexType name="InternalWellType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="Perforation" type="PerforationType" />
</xsd:choice>
<!--logLevel => Log level-->
<xsd:attribute name="logLevel" type="integer" default="0" />
<!--minElementLength => Minimum length of a well element, computed as (segment length / number of elements per segment ) [m]-->
<xsd:attribute name="minElementLength" type="real64" default="0.001" />
<!--minSegmentLength => Minimum length of a well segment [m]-->
<xsd:attribute name="minSegmentLength" type="real64" default="0.01" />
<!--numElementsPerSegment => Number of well elements per polyline segment-->
<xsd:attribute name="numElementsPerSegment" type="integer" use="required" />
<!--polylineNodeCoords => Physical coordinates of the well polyline nodes-->
<xsd:attribute name="polylineNodeCoords" type="real64_array2d" use="required" />
<!--polylineSegmentConn => Connectivity of the polyline segments-->
<xsd:attribute name="polylineSegmentConn" type="globalIndex_array2d" use="required" />
<!--radius => Radius of the well [m]-->
<xsd:attribute name="radius" type="real64" use="required" />
<!--wellControlsName => Name of the set of constraints associated with this well-->
<xsd:attribute name="wellControlsName" type="groupNameRef" use="required" />
<!--wellRegionName => Name of the well element region-->
<xsd:attribute name="wellRegionName" type="groupNameRef" use="required" />
<!--name => A name is required for any non-unique nodes-->
<xsd:attribute name="name" type="groupName" use="required" />
</xsd:complexType>
.... For example I know that "globalIndex" is an integer or "R1Tensor" and "globalIndex_array" arenumpy 1d arrays. In an xml I have: <ConstantPermeability
name="rockPermeability"
permeabilityComponents="{ 6.7593e-14, 6.7593e-14, 6.7593e-15 }"/> I don't know what can be the most effective.. I imagine I need to write somewhere how to deserizlize the string into the class I want (numpy or array of strings or whatever) ? |
I have a minimal reproducer: test_xsdata.zip |
@tefra I managed to get the numpy types work. I didn't know that dataclass is only for Elements and not for Attributes. |
We need to extend the filter strategies of the configuration to allow people to define a custom list classes they want to keep to matter what. |
I have zero interest on this one, it requires a lot of work and goes against the xsdata architecture to simplify the generated types. I can see the argument that we are missing validations of restrictions but having standalone classes for primitive types is just too much. Although if someone manages to implement this one as a feature behind a config, I will accept it as contribution. |
I understand the desire to minimize "unnecessary" class types, but in some cases, there is reason to create all SimpleType classes from an XSD. For example, if classes are created for SimpleTypes, then they can be used as classes in the rest of the code. For example, I have a SimpleType called
DistanceType
which for my use is defined with units of Meters, and is non-negative. I want a class for this so that I can use this type anywhere else in the schema that usesDistanceType
.Here is an example:
I would like and option to explicitly create the DistanceType class.
The text was updated successfully, but these errors were encountered: