Skip to content

Commit

Permalink
Merge pull request #74 from InseeFr/develop
Browse files Browse the repository at this point in the history
adding suggester
  • Loading branch information
ORogel authored Oct 19, 2022
2 parents 572dbdd + d59b1bf commit d217ae7
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>fr.insee.lunatic</groupId>
<artifactId>lunatic-model</artifactId>
<packaging>jar</packaging>
<version>2.2.3</version>
<version>2.2.10</version>
<name>Lunatic Model</name>
<description>Classes and converters for the Lunatic model</description>
<url>http://www.insee.fr</url>
Expand Down Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>
<version>2.17.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
61 changes: 61 additions & 0 deletions src/main/resources/xsd/LunaticModel.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<xs:extension base="ComponentType">
<xs:sequence>
<xs:element name="components" type="ComponentType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="suggesters" type="SuggesterType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="variables" type="IVariableType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
Expand Down Expand Up @@ -148,6 +149,64 @@
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>


<xs:complexType name="SuggesterType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="fields" type="SuggesterField" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="max" type="xs:integer" minOccurs="0"/>
<xs:element name="stopWords" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="order" type="SuggesterOrder" minOccurs="0"/>
<xs:element name="queryParser" type="SuggesterQueryParser"/>
<xs:element name="url" type="xs:string" minOccurs="0"/>
<xs:element name="version" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SuggesterField">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:element name="rules" type="xs:string"/>
<xs:element name="rulesA" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
</xs:choice>
<xs:element name="language" type="xs:string" minOccurs="0"/>
<xs:element name="min" type="xs:integer" minOccurs="0"/>
<xs:element name="stemmer" type="xs:boolean" minOccurs="0"/>
<xs:element name="synonyms" type="FieldSynonym" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="FieldSynonym">
<xs:sequence>
<xs:element name="source" type="xs:string" minOccurs="1"/>
<xs:element name="target" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SuggesterOrder">
<xs:sequence>
<xs:element name="field" type="xs:string"/>
<xs:element name="type" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SuggesterQueryParser">
<xs:sequence>
<xs:element name="type" type="xs:string"/>
<xs:element name="params" type="SuggesterQueryParserParams" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SuggesterQueryParserParams">
<xs:sequence>
<xs:element name="language" type="xs:string" minOccurs="0"/>
<xs:element name="min" type="xs:integer" minOccurs="0"/>
<xs:element name="pattern" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>


<xs:complexType name="IVariableType" abstract="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
Expand All @@ -166,6 +225,7 @@
<xs:element name="expression" type="xs:string" minOccurs="0"/>
<xs:element name="bindingDependencies" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="shapeFrom" type="xs:string" minOccurs="0"/>
<xs:element name="inFilter" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
Expand Down Expand Up @@ -439,6 +499,7 @@
<xs:enumeration value="INSTRUCTION"/>
<xs:enumeration value="COMMENT"/>
<xs:enumeration value="HELP"/>
<xs:enumeration value="CODECARD"/>
<xs:enumeration value="WARNING"/>
<xs:enumeration value="STATEMENT"/>
</xs:restriction>
Expand Down
65 changes: 64 additions & 1 deletion src/main/resources/xsd/LunaticModelFlat.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<xs:extension base="ComponentType">
<xs:sequence>
<xs:element name="components" type="ComponentType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="suggesters" type="SuggesterType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="variables" type="IVariableType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
Expand Down Expand Up @@ -93,7 +94,9 @@
<xs:element name="controls" type="ControlType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="hierarchy" type="hierarchy" minOccurs="0"/>
<xs:element name="missingResponse" type="ResponseType" minOccurs="0"/>


<xs:element name="storeName" minOccurs="0"/>

<xs:element name="bindingDependencies" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
Expand Down Expand Up @@ -134,12 +137,70 @@
<xs:enumeration value="Dropdown"/>
<xs:enumeration value="Textarea"/>
<xs:enumeration value="FilterDescription"/>
<xs:enumeration value="Suggester"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="ResponseType">
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>

<xs:complexType name="SuggesterType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="fields" type="SuggesterField" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="max" type="xs:integer" minOccurs="0"/>
<xs:element name="stopWords" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="order" type="SuggesterOrder" minOccurs="0"/>
<xs:element name="queryParser" type="SuggesterQueryParser"/>
<xs:element name="url" type="xs:string" minOccurs="0"/>
<xs:element name="version" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SuggesterField">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:element name="rules" type="xs:string"/>
<xs:element name="rulesA" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
</xs:choice>
<xs:element name="language" type="xs:string" minOccurs="0"/>
<xs:element name="min" type="xs:integer" minOccurs="0"/>
<xs:element name="stemmer" type="xs:boolean" minOccurs="0"/>
<xs:element name="synonyms" type="FieldSynonym" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="FieldSynonym">
<xs:sequence>
<xs:element name="source" type="xs:string" minOccurs="1"/>
<xs:element name="target" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SuggesterOrder">
<xs:sequence>
<xs:element name="field" type="xs:string"/>
<xs:element name="type" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SuggesterQueryParser">
<xs:sequence>
<xs:element name="type" type="xs:string"/>
<xs:element name="params" type="SuggesterQueryParserParams" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SuggesterQueryParserParams">
<xs:sequence>
<xs:element name="language" type="xs:string" minOccurs="0"/>
<xs:element name="min" type="xs:integer" minOccurs="0"/>
<xs:element name="pattern" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>


<xs:complexType name="IVariableType" abstract="true">
<xs:sequence>
Expand All @@ -159,6 +220,7 @@
<xs:element name="expression" type="xs:string" minOccurs="0"/>
<xs:element name="bindingDependencies" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="shapeFrom" type="xs:string" minOccurs="0"/>
<xs:element name="inFilter" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
Expand Down Expand Up @@ -432,6 +494,7 @@
<xs:enumeration value="INSTRUCTION"/>
<xs:enumeration value="COMMENT"/>
<xs:enumeration value="HELP"/>
<xs:enumeration value="CODECARD"/>
<xs:enumeration value="WARNING"/>
<xs:enumeration value="STATEMENT"/>
</xs:restriction>
Expand Down
14 changes: 11 additions & 3 deletions src/main/resources/xslt/json-cleaner.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
<xsl:copy-of select="xml-to-json($output-xml, map{'indent':true()})"/>
</xsl:template>

<!-- delete type attribute -->
<xsl:template match="*[@key='type']" mode="clean"/>
<!-- delete type attribute except when key is linked to the suggesters block-->
<xsl:template match="*[@key='type'][not(ancestor::*[@key=('suggesters')])]" mode="clean"/>
<!-- delete map useless inside array -->
<xsl:template match="*[local-name(.)='map'][parent::*[@key=('PREVIOUS','COLLECTED','FORCED','EDITED','INPUTED') and local-name(.)='array'] | parent::*[@key=('values')]]" mode="clean">
<xsl:apply-templates mode="clean"/>
</xsl:template>
<xsl:template match="*[local-name(.)='map'][parent::*[@key='value' and local-name(.)='array'] or (self::*[@key='value'] and preceding-sibling::*[@key='variableType'])]" mode="clean">
<xsl:apply-templates mode="clean"/>
</xsl:template>
<!-- delete key attribue for array inside array -->
<!-- delete key attribute for array inside array -->
<xsl:template match="*[local-name(.)='array' and @key=('PREVIOUS','COLLECTED','FORCED','EDITED','INPUTED','value')][ancestor::*[local-name(.)='array' and @key=('PREVIOUS','COLLECTED','FORCED','EDITED','INPUTED','value')]]" mode="clean">
<xsl:copy>
<xsl:apply-templates mode="clean"/>
Expand All @@ -50,6 +50,14 @@
</xsl:copy>
</xsl:template>

<!-- rename the rulesA key of suggesters to rules -->
<xsl:template match="*[@key='rulesA']" mode="clean">
<xsl:copy>
<xsl:attribute name="key" select="'rules'"/>
<xsl:apply-templates select="node()" mode="clean"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*|node()" mode="clean">
<xsl:choose>
<xsl:when test="self::text()">
Expand Down

0 comments on commit d217ae7

Please sign in to comment.