How to create oak:index in AEM programatically - aem

How do I create oak:index programatically using xml files so that I don't have to create it manually in AEM6.5?

The best approach is, to create a content package with indexes. This would also be AEMaaCS compatible.
Here is a sample pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ====================================================================== -->
<!-- P A R E N T P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<parent>
...
</parent>
<!-- ====================================================================== -->
<!-- P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<artifactId>com.acme.ui.indexes</artifactId>
<packaging>content-package</packaging>
<name>ACME - UI Indexes</name>
<description>oak:index package for ACME</description>
<!-- ====================================================================== -->
<!-- B U I L D D E F I N I T I O N -->
<!-- ====================================================================== -->
<build>
<resources>
<resource>
<directory>${basedir}/src/main/content/jcr_root</directory>
</resource>
</resources>
<plugins>
<!-- ====================================================================== -->
<!-- V A U L T P A C K A G E P L U G I N S -->
<!-- ====================================================================== -->
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<configuration>
<group>com.acme.aem</group>
<name>com.acme.ui.indexes</name>
<packageType>application</packageType>
<allowIndexDefinitions>true</allowIndexDefinitions>
<properties>
<!-- Best practise for Oak:Indexes package (but only here) -->
<noIntermediateSaves>true</noIntermediateSaves>
</properties>
<validatorsSettings>
<jackrabbit-nodetypes>
<options>
<!-- As /oak:index is a nt:unstructured, this shall be the default parent-node-type -->
<defaultNodeType>nt:unstructured</defaultNodeType>
</options>
</jackrabbit-nodetypes>
</validatorsSettings>
<repositoryStructurePackages>
<repositoryStructurePackage>
<groupId>com.acme.aem</groupId>
<artifactId>com.acme.ui.apps.structure</artifactId>
</repositoryStructurePackage>
</repositoryStructurePackages>
</configuration>
</plugin>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<verbose>true</verbose>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
<!-- ====================================================================== -->
<!-- D E P E N D E N C I E S -->
<!-- ====================================================================== -->
<dependencies>
<dependency>
<groupId>com.acme.aem</groupId>
<artifactId>com.acme.ui.apps.structure</artifactId>
<version>${project.version}</version>
<type>zip</type>
</dependency>
</dependencies>
</project>
As you have mixed content below /oak:index, you need to specify each custom index in the filter.xml
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/oak:index/experienceFragmentsIndex-3-custom-1" />
<filter root="/oak:index/productCatalogLuceneIndex-custom-1" />
</workspaceFilter>
The index-names should follow the convention described in the official documentation.
https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/operations/indexing.html?lang=en

Related

Difficulty using buoyancy plugin (libBuoyancyPlugin.so) for my gazebo model(for ROS1)

RE-EDIT:
I want to apply bouyancy plugin my model which is made of 3 links. Do I need to apply the bouyancy plugin to all of the links for my model to float? Or do I just need to apply it to the base_link. The collision geometries for all of links are .dae files. But I have the gemotry of my base_link as a sphere for my Buoyancy plugin. Below is my .urdf.xacro file. For now, my model still phases through my world, so buoyancy isn't working. Not quite sure what I'm doing wrong.
<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro" name="wam-v">
<xacro:include filename="properties.urdf.xacro"/>
<link name="base_link">
<visual>
<geometry>
<mesh filename="package://freddy/mesh/WAM-V.dae"/>
</geometry>
</visual>
<collision name="base_link_collision">
<geometry>
<mesh filename="package://freddy/mesh/WAM-V.dae"/>
<!--sphere radius="1.5" /-->
</geometry>
</collision>
<inertial>
<mass value="247.07"/>
<inertia ixx="200" ixy="0.03" ixz="3.09" iyy="500" iyz="-0.05" izz="165.39"/>
<!--inertia ixx="198.828" ixy="0" ixz="0" iyy="198.828" iyz="0" izz="198.828"/-->
</inertial>
</link>
<joint name="base_link_joint" type="fixed">
<origin xyz="0 0 1.84"/>
<parent link="base_footprint"/>
<child link="base_link"/>
</joint>
<link name="base_footprint"/>
<link name="front_camera_link"/>
<joint name="front_camera_joint" type="fixed">
<origin xyz="1.2 0 0"/>
<parent link="base_link"/>
<child link="front_camera_link"/>
</joint>
<link name="left_camera_link"/>
<joint name="left_camera_joint" type="fixed">
<origin xyz="0 0.5 0" rpy="0 0 ${pi/2}"/>
<parent link="base_link"/>
<child link="left_camera_link"/>
</joint>
<link name="right_camera_link"/>
<joint name="right_camera_joint" type="fixed">
<origin xyz="0 -0.5 0" rpy="0 0 ${-pi/2}"/>
<parent link="base_link"/>
<child link="right_camera_link"/>
</joint>
<link name="rear_camera_link"/>
<joint name="rear_camera_joint" type="fixed">
<origin xyz="-0.5 0 0" rpy="0 0 ${pi}"/>
<parent link="base_link"/>
<child link="rear_camera_link"/>
</joint>
<link name="scan"/>
<joint name="scan_joint" type="fixed">
<origin xyz="1.5 0 -1" rpy="0 0 0"/>
<parent link="base_link"/>
<child link="scan"/>
</joint>
<link name="right_motor">
<visual>
<geometry>
<mesh filename="package://freddy/mesh/PROPELLER.dae"/>
</geometry>
</visual>
<collision name="right_motor_collision">
<geometry>
<mesh filename="package://freddy/mesh/PROPELLER.dae"/>
</geometry>
</collision>
<inertial>
<mass value="0.01"/>
<inertia ixx="0.00086" ixy="0.00" ixz="0.00" iyy="0.00086" iyz="0.00" izz="0.0017"/>
</inertial>
</link>
<joint name="right_motor_joint" type="continuous">
<origin xyz="${motor_position_x} -${motor_position_y} ${motor_position_z}"/>
<parent link="base_link"/>
<child link="right_motor"/>
<limit effort="0.5293" velocity="100${pi}" />
</joint>
<link name="left_motor">
<visual>
<geometry>
<mesh filename="package://freddy/mesh/PROPELLER.dae"/>
</geometry>
</visual>
<collision name="left_motor_collision">
<geometry>
<mesh filename="package://freddy/mesh/PROPELLER.dae"/>
</geometry>
</collision>
<inertial>
<mass value="0.01"/>
<inertia ixx="0.00086" ixy="0.00" ixz="0.00" iyy="0.00086" iyz="0.00" izz="0.0017"/>
</inertial>
</link>
<joint name="left_motor_joint" type="continuous">
<origin xyz="${motor_position_x} ${motor_position_y} ${motor_position_z}"/>
<parent link="base_link"/>
<child link="left_motor"/>
<limit effort="0.5293" velocity="100${pi}" />
</joint>
<link name="gps"/>
<joint name="gps_joint" type="fixed">
<origin xyz="0.8 0 0"/>
<parent link="base_link"/>
<child link="gps"/>
</joint>
<transmission name="right_motor_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="right_motor_joint">
<hardwareInterface>VelocityJointInterface</hardwareInterface>
</joint>
<actuator name="right_motor_actuator">
<hardwareInterface>VelocityJointInterface</hardwareInterface>
<mechanicalReduction>30</mechanicalReduction>
</actuator>
</transmission>
<transmission name="left_motor_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="left_motor_joint">
<hardwareInterface>VelocityJointInterface</hardwareInterface>
</joint>
<actuator name="left_motor_actuator">
<hardwareInterface>VelocityJointInterface</hardwareInterface>
<mechanicalReduction>30</mechanicalReduction>
</actuator>
</transmission>
<!--gazebo>
<plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
<commandTopic>cmd_vel</commandTopic>
<odometryTopic>odom</odometryTopic>
<odometryFrame>odom</odometryFrame>
<odometrySource>world</odometrySource>
<publishOdomTF>true</publishOdomTF>
<robotBaseFrame>base_footprint</robotBaseFrame>
<publishWheelTF>false</publishWheelTF>
<publishTf>true</publishTf>
<publishWheelJointState>true</publishWheelJointState>
<legacyMode>false</legacyMode>
<updateRate>30</updateRate>
<leftJoint>left_motor_joint</leftJoint>
<rightJoint>right_motor_joint</rightJoint>
<wheelSeparation>2.054</wheelSeparation>
<wheelDiameter>0.098</wheelDiameter>
<wheelAcceleration>1</wheelAcceleration>
<wheelTorque>10</wheelTorque>
<rosDebugLevel>na</rosDebugLevel>
</plugin>
</gazebo-->
<gazebo reference="scan">
<plugin name="BuoyancyPlugin" filename="libBuoyancyPlugin.so">
<!--a viscous liquid -->
<fluid_density>1000</fluid_density>
<link name="base_link">
<center_of_volume>0 0 1.84</center_of_volume>
<volume>47.712</volume>
</link>
<geometry><sphere radius="2.25" /></geometry>
</plugin>
</gazebo>
<xacro:include filename="camera.urdf.xacro"/>
<xacro:camera prefix="front"/>
<xacro:camera prefix="right"/>
<xacro:camera prefix="left"/>
<xacro:camera prefix="rear"/>
<xacro:include filename="$(find velodyne_description)/urdf/VLP-16.urdf.xacro"/>
<VLP-16 parent="base_link" name="velodyne" topic="/velodyne_points">
<origin xyz="0.8 0 0.3" rpy="0 0 0" />
</VLP-16>
<gazebo reference="scan">
<material>Gazebo/Blue</material>
<turnGravityOff>false</turnGravityOff>
<sensor type="ray" name="scan_sensor">
<pose>0 0 0 0 0 0</pose>
<visualize>false</visualize>
<update_rate>40</update_rate>
<ray>
<scan>
<horizontal>
<samples>720</samples>
<resolution>1</resolution>
<min_angle>-1.570796</min_angle>
<max_angle>1.570796</max_angle>
</horizontal>
</scan>
<range>
<min>1</min>
<max>30.0</max>
<resolution>0.001</resolution>
</range>
</ray>
<plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so">
<topicName>/scan</topicName>
<frameName>scan</frameName>
</plugin>
</sensor>
</gazebo>
<gazebo reference="front_camera_link">
<sensor type="camera" name="front">
<update_rate>30.0</update_rate>
<!--camera name="head"-->
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>800</width>
<height>800</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
<noise>
<type>gaussian</type>
<!-- Noise is sampled independently per pixel on each frame.
That pixel's noise value is added to each of its color
channels, which at that point lie in the range [0,1].-->
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
<!--/camera-->
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
<alwaysOn>true</alwaysOn>
<updateRate>0.0</updateRate>
<cameraName>wam_v/front</cameraName>
<imageTopicName>image_raw</imageTopicName>
<cameraInfoTopicName>camera_info</cameraInfoTopicName>
<frameName>front_camera_link</frameName>
<hackBaseline>0.07</hackBaseline>
<distortionK1>0.0</distortionK1>
<distortionK2>0.0</distortionK2>
<distortionK3>0.0</distortionK3>
<distortionT1>0.0</distortionT1>
<distortionT2>0.0</distortionT2>
</plugin>
</sensor>
</gazebo>
<gazebo reference="right_camera_link">
<sensor type="camera" name="right">
<update_rate>30.0</update_rate>
<!--camera name="head"-->
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>800</width>
<height>800</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
<noise>
<type>gaussian</type>
<!-- Noise is sampled independently per pixel on each frame.
That pixel's noise value is added to each of its color
channels, which at that point lie in the range [0,1].-->
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
<!--/camera-->
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
<alwaysOn>true</alwaysOn>
<updateRate>0.0</updateRate>
<cameraName>wam_v/right</cameraName>
<imageTopicName>image_raw</imageTopicName>
<cameraInfoTopicName>camera_info</cameraInfoTopicName>
<frameName>right_camera_link</frameName>
<hackBaseline>0.07</hackBaseline>
<distortionK1>0.0</distortionK1>
<distortionK2>0.0</distortionK2>
<distortionK3>0.0</distortionK3>
<distortionT1>0.0</distortionT1>
<distortionT2>0.0</distortionT2>
</plugin>
</sensor>
</gazebo>
<gazebo reference="left_camera_link">
<sensor type="camera" name="left">
<update_rate>30.0</update_rate>
<!--camera name="head"-->
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>800</width>
<height>800</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
<noise>
<type>gaussian</type>
<!-- Noise is sampled independently per pixel on each frame.
That pixel's noise value is added to each of its color
channels, which at that point lie in the range [0,1].-->
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
<!--/camera-->
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
<alwaysOn>true</alwaysOn>
<updateRate>0.0</updateRate>
<cameraName>wam_v/left</cameraName>
<imageTopicName>image_raw</imageTopicName>
<cameraInfoTopicName>camera_info</cameraInfoTopicName>
<frameName>left_camera_link</frameName>
<hackBaseline>0.07</hackBaseline>
<distortionK1>0.0</distortionK1>
<distortionK2>0.0</distortionK2>
<distortionK3>0.0</distortionK3>
<distortionT1>0.0</distortionT1>
<distortionT2>0.0</distortionT2>
</plugin>
</sensor>
</gazebo>
<gazebo reference="rear_camera_link">
<sensor type="camera" name="rear">
<update_rate>30.0</update_rate>
<!--camera name="head"-->
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>800</width>
<height>800</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
<noise>
<type>gaussian</type>
<!-- Noise is sampled independently per pixel on each frame.
That pixel's noise value is added to each of its color
channels, which at that point lie in the range [0,1].-->
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
<!--/camera-->
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
<alwaysOn>true</alwaysOn>
<updateRate>0.0</updateRate>
<cameraName>wam_v/rear</cameraName>
<imageTopicName>image_raw</imageTopicName>
<cameraInfoTopicName>camera_info</cameraInfoTopicName>
<frameName>back_camera_link</frameName>
<hackBaseline>0.07</hackBaseline>
<distortionK1>0.0</distortionK1>
<distortionK2>0.0</distortionK2>
<distortionK3>0.0</distortionK3>
<distortionT1>0.0</distortionT1>
<distortionT2>0.0</distortionT2>
</plugin>
</sensor>
</gazebo>
</robot>

Pressure topic is not published when add barometric pressure Sensor with geometry_msgs/PointStamped

To use http://wiki.ros.org/hector_pose_estimation?distro=noetic hector_pose_estimation package i need to fuse IMU and barometric pressure Sensor with geometry_msgs/PointStamped So I add such barometric pressure Sensor with geometry_msgs/PointStamped with gazebo_ros_plugins.
Here is the urdf.xacro of the barometric pressure Sensor
<?xml version="1.0"?>
<!-- Copyright (c) 2016 The UUV Simulator Authors.
All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:macro name="no_collision">
<collision>
<geometry>
<cylinder length="${0.000001}" radius="${0.000001}" />
</geometry>
<origin xyz="0 0 0" rpy="0 ${0.5*pi} 0"/>
</collision>
</xacro:macro>
<xacro:macro name="default_pressure_macro" params="namespace parent_link *origin">
<xacro:pressure_plugin_macro
namespace="${namespace}"
suffix=""
parent_link="${parent_link}"
topic="pressure"
mass="0.015"
update_rate="10"
range="30000"
noise_sigma="3.0"
noise_amplitude="0.0"
estimateDepth="false"
standardPressure="101.325"
kPaPerM="9.80638">
<inertia ixx="0.00001" ixy="0.0" ixz="0.0" iyy="0.00001" iyz="0.0" izz="0.00001" />
<xacro:insert_block name="origin" />>
</xacro:pressure_plugin_macro>
</xacro:macro>
<xacro:macro name="default_pressure" params="namespace parent_link *origin">
<xacro:pressure_plugin_macro
namespace="${namespace}"
suffix=""
parent_link="${parent_link}"
topic="pressure"
mass="0.015"
update_rate="10"
range="30000"
noise_sigma="3.0"
noise_amplitude="0.0"
estimateDepth="false"
standardPressure="101.325"
kPaPerM="9.80638">
<inertia ixx="0.00001" ixy="0.0" ixz="0.0" iyy="0.00001" iyz="0.0" izz="0.00001" />
<xacro:insert_block name="origin" />
</xacro:pressure_plugin_macro>
</xacro:macro>
<xacro:macro name="pressure_plugin_macro"
params="namespace suffix parent_link topic mass update_rate
range noise_sigma noise_amplitude estimateDepth standardPressure kPaPerM
*inertia *origin">
<link name="${namespace}/pressure${suffix}_link">
<inertial>
<xacro:insert_block name="inertia" />
<mass value="${mass}" /> <!-- [kg] -->
<origin xyz="0 0 0" rpy="0 0 0" />
</inertial>
<visual>
<geometry>
<mesh filename="file://$(find uuv_sensor_ros_plugins)/meshes/pressure.dae" scale="1 1 1"/>
</geometry>
</visual>
<xacro:no_collision/>
</link>
<joint name="${namespace}/pressure${suffix}_joint" type="revolute">
<xacro:insert_block name="origin" />
<parent link="${parent_link}" />
<child link="${namespace}/pressure${suffix}_link" />
<limit upper="0" lower="0" effort="0" velocity="0" />
<axis xyz="1 0 0"/>
</joint>
<gazebo>
<plugin filename="librotors_gazebo_pressure_plugin.so" name="rotors_gazebo_pressure_sensor${suffix}_plugin">
<robot_namespace>${namespace}</robot_namespace> <!-- (string, required): ros namespace in which the messages are published -->
<linkName>${namespace}/pressure${suffix}_link</linkName> <!-- (string, required): name of the body which holds the IMU sensor -->
<sensor_topic>${topic}</sensor_topic> <!-- (string): name of the sensor output topic and prefix of service names (defaults to imu) -->
<update_rate>${update_rate}</update_rate> <!-- Update period of accelerometer and gyroscope [s] -->
<saturation>${range}</saturation> <!-- measurement range [kPa] -->
<noise_sigma>${noise_sigma}</noise_sigma> <!-- measurement stddev [kPa] -->
<noise_amplitude>${noise_amplitude}</noise_amplitude>
<estimate_depth_on>${estimateDepth}</estimate_depth_on> <!-- infer depth? -->
<standard_pressure>${standardPressure}</standard_pressure> <!-- pressure at sea level (depth 0 m) [kPa] -->
<kPa_per_meter>${kPaPerM}</kPa_per_meter> <!-- increase in pressure [kPa] per [m] in increased depth -->
<enable_gazebo_messages>false</enable_gazebo_messages>
</plugin>
</gazebo>
</xacro:macro>
</robot>
I can compile and run Gazebo and got this line in blue [Dbg] [gazebo_pressure_plugin.cpp:39] _model = rexrov2
When run rostopic list the pressure topic is not published.The plugin file librotors_gazebo_pressure_plugin is there.
Any help?

how to remove space around SvgPicture in flutter?

Whenever I add a SvgPicture somehow there is extra space that is created between the container, I have no idea how this space is being created.
I have tried changing the width and height, changing the actual size of SVG using Inkscape and changing the fit of the SvgPicture but something fixed the issue.
IconButton(icon: SvgPicture.asset('assets/icons/drawing.svg'), onPressed: null)
Here is the image of this code:
IconButton(icon: SvgPicture.asset('assets/icons/drawing.svg', width: 15), onPressed: null)
Here is the image of this code:
The actual SVG file has no space around it and is completely filled to the canvas.
Note: There is nothing inside the column except this SVG.
SVG CODE
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 5.2916665 5.2916665"
version="1.1"
id="svg882">
<defs
id="defs876" />
<metadata
id="metadata879">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1">
<g
id="g14"
transform="matrix(0.01414769,0,0,0.01414769,0,-0.32822657)">
<g
id="g12">
<g
id="g10">
<path
d="M 327.6,67.6 C 320.8,42 297.2,23.2 270.4,23.2 H 59.2 C 26.8,23.2 0,49.6 0,82.4 v 98 C 0,208 19.6,232 46,238 c 6.4,25.6 29.6,44.4 57.2,44.4 h 8.8 v 59.2 c 0,3.2 2,6.4 4.8,8 1.2,0.4 2.4,0.8 4,0.8 2,0 3.6,-0.8 5.2,-2 l 85.6,-66 h 102.8 c 32.4,0 59.2,-26.4 59.2,-59.2 v -98 c 0,-28 -19.6,-51.6 -46,-57.6 z M 44,125.2 v 94 C 28.4,213.2 17.6,198 17.6,180.4 v -98 c 0,-22.8 18.8,-41.6 41.6,-41.6 h 211.6 c 16.8,0 31.6,10.4 38,25.2 H 103.2 C 70.8,66 44,92.4 44,125.2 Z m 312.4,98 H 356 c 0,22.8 -18.8,41.6 -41.6,41.6 H 208.8 c -2,0 -4,0.8 -5.2,2 l -74,57.2 v -50.4 c 0,-4.8 -4,-8.8 -8.8,-8.8 H 103.2 C 80.4,264.8 61.6,246 61.6,223.2 v -98 c 0,-22.8 18.8,-41.6 41.6,-41.6 h 211.6 c 22.8,0 41.6,18.8 41.6,41.6 z"
id="path2" />
<path
d="m 298.8,122.4 h -180 c -4.8,0 -8.8,4 -8.8,8.8 0,4.8 4,8.8 8.8,8.8 h 180 c 4.8,0 8.8,-4 8.8,-8.8 0,-4.8 -4,-8.8 -8.8,-8.8 z"
id="path4" />
<path
d="m 298.8,160.8 h -180 c -4.8,0 -8.8,4 -8.8,8.8 0,4.8 4,8.8 8.8,8.8 h 180 c 4.8,0 8.8,-4 8.8,-8.8 0,-4.8 -4,-8.8 -8.8,-8.8 z"
id="path6" />
<path
d="m 298.8,199.6 h -180 c -4.8,0 -8.8,4 -8.8,8.8 0,4.8 4,8.8 8.8,8.8 h 180 c 4.8,0 8.8,-4 8.8,-8.8 0,-5.2 -4,-8.8 -8.8,-8.8 z"
id="path8" />
</g>
</g>
</g>
</g>
</svg>

Is it possible to add transformation code to pmml?

I run a linear regression code and generated a pmml. In my pmml code there are data types and regression table info. I have a pmml code like that
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<PMML version="4.2"
xmlns="http://www.dmg.org/PMML-4_2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<Application name="SAS(r)" version="9.4"/>
<Timestamp>2016-05-27 09:58:01</Timestamp>
</Header>
<DataDictionary numberOfFields="10">
<DataField name="Invoice" optype="continuous" dataType="double"/>
<DataField name="ZINT_Cylinders" optype="continuous" dataType="double"/>
<DataField name="ZINT_EngineSize" optype="continuous" dataType="double"/>
</DataDictionary>
<TransformationDictionary/>
<RegressionModel functionName="regression" targetFieldName="Invoice" normalizationMethod="none">
<MiningSchema>
<MiningField name="ZINT_Cylinders" usageType="active" optype="continuous"/>
<MiningField name="ZINT_EngineSize" usageType="active" optype="continuous"/>
</MiningSchema>
<Output>
<OutputField name="P_Invoice" displayName="Predicted: Invoice" optype="continuous" dataType="double" targetField="Invoice" feature="predictedValue"/>
</Output>
<Targets>
<Target field="Invoice" optype="continuous">
<TargetValue defaultValue="30014.700935"/>
</Target>
</Targets>
<LocalTransformations/>
<RegressionTable intercept="-4919.70174">
<NumericPredictor name="ZINT_Cylinders" coefficient="-0.007378626"/>
<NumericPredictor name="ZINT_EngineSize" coefficient="-0.147331595"/>
</RegressionTable>
</RegressionModel>
</PMML>
Before the regression step, I want to transform the my source data. For example I want to add these case when structure to my pmml. Is it possible to do this?
SELECT Invoice,
CASE
WHEN EngineSize < 2.9 THEN 20304.5142857143
WHEN EngineSize < 4.1 THEN 30378.8789808917
WHEN EngineSize >= 4.1 THEN 47119.9791666667
ELSE 30014.7009345794
END AS ZINT_EngineSize,
CASE
WHEN Cylinders < 4.5 THEN 18349.4452554745
WHEN Cylinders < 7 THEN 29472.3819095477
WHEN Cylinders >= 7 THEN 48558.847826087
ELSE 30014.7009345794
END AS ZINT_Cylinders
FROM MYSOURCE.MYTABLE;
You can use the Discretize transformation for the job:
<DerivedField name="ZINT_EngineSize" dataType="double" optype="continuous">
<Discretize field="EngineSize">
<DiscretizeBin binValue="20304.5142857143">
<!-- EngineSize < 2.9 -->
<Interval closure="openOpen" rightMargin="2.9"/>
</DiscretizeBin>
<DiscretizeBin binValue="30378.8789808917">
<!-- EngineSize >= 2.9 && EngineSize < 4.1 -->
<Interval closure="closedOpen" leftMargin="2.9" rightMargin="4.1"/>
</DiscretizeBin>
<DiscretizeBin binValue="47119.9791666667">
<!-- EngineSize >= 4.1 -->
<Interval closure="closedOpen" leftMargin="4.1"/>
</DiscretizeBin>
</Discretize>
</DerivedField>
You could build a parser for SAS script, and automate the generation and embedding of Discretize elements using the JPMML-Model library.

Relationship between integers and their names - Prolog

I'm trying to explore the concepts of natural numbers, Peano numbers, arithmetic, etc. in Prolog. Right now I'm trying to create a predicate that will allow me to enter the name of any number and get it's numerical value (or vice versa). How would I go about this? My idea was that I would translate the numbers given and them add them together using the plus function (e.g. one hundred and forty-five: one, hundred = 100, and = 0, forty = 40, five = 5 -> 100 + 0 + 40 + 5 = 145.
Here's an example of some queries:
?- numnames(X, 375).
X = [three, hundred, and, seventy, five] ;
false.
?- numnames([seven], 7).
true ;
false.
Here are some of my exhaustive facts (I just picked some that would address a certain category):
numnames([],0).
numnames(and,0).
numnames([one],1).
numnames([ninety],90).
numnames([one, hundred], 100).
I'm just confused as to how to translate the numbers before the arithmetic, and also where/when do I stop making exhaustive facts and start making rules?
Thanks for the help.
This is a nice application for Prolog grammar rules or DCGs (basically syntactic sugar that hides some list manipulation and has a relatively straightforward translation to normal Prolog rules).
num_0_999(0) --> [zero].
num_0_999(N) --> num_1_99(N).
num_0_999(N) --> num_100_999(N).
num_1_99(N) --> num_1_9(N).
num_1_99(N) --> num_10_19(N).
num_1_99(N) --> decade(T), opt_1_9(U), {N is T+U}.
num_100_999(N) --> num_1_9(H), [hundred], opt_1_99(S), {N is 100*H+S}.
opt_1_9(0) --> [].
opt_1_9(N) --> num_1_9(N).
opt_1_99(0) --> [].
opt_1_99(N) --> [and], num_1_99(N).
num_1_9(1) --> [one]. num_1_9(2) --> [two]. num_1_9(3) --> [three].
num_1_9(4) --> [four]. num_1_9(5) --> [five]. num_1_9(6) --> [six].
num_1_9(7) --> [seven]. num_1_9(8) --> [eight]. num_1_9(9) --> [nine].
num_10_19(10) --> [ten]. num_10_19(11) --> [eleven].
num_10_19(12) --> [twelve]. num_10_19(13) --> [thirteen].
num_10_19(14) --> [fourteen]. num_10_19(15) --> [fifteen].
num_10_19(16) --> [sixteen]. num_10_19(17) --> [seventeen].
num_10_19(18) --> [eighteen]. num_10_19(19) --> [nineteen].
decade(20) --> [twenty]. decade(30) --> [thirty].
decade(40) --> [forty]. decade(50) --> [fifty].
decade(60) --> [sixty]. decade(70) --> [seventy].
decade(80) --> [eighty]. decade(90) --> [ninety].
This work both ways (and can enumerate all the numbers):
?- phrase(num_0_999(46), Name).
Name = [forty, six]
Yes (0.00s cpu, solution 1, maybe more)
?- phrase(num_0_999(N), [forty, six]).
N = 46
Yes (0.00s cpu, solution 1, maybe more)
[I had originally used a #=/2 constraint instead of is/2 to make the code work in both modes, but was reminded by #CapelliC's post that the same can be achieved in plain Prolog by moving the arithmetic to the end of the respective rules...]
I have an extravagant solution, which, nevertheless, could be practical for some situations.
Suppose the max number you plan to use is not too big, maybe a 1000 or 10000. And also you don't want to spend too much time creating Prolog program, don't want to deal with corner cases and are afraid of spelling errors (for example, because you are not a native English speaker, like me).
Then you can generate your Prolog program (list of facts) with another tool. Common Lisp has a standard tool to convert numbers to English words. Let's use it:
(defun generate-prolog (k)
(loop for n from 1 to k do
(format t "numnames([~a], ~a). ~%"
(substitute #\, #\Space
(remove #\,
(substitute #\Space #\- (format nil "~R" n)) ) ) n) ) )
(generate-prolog 1000)
Fragment of the Prolog program generated with CLISP (other Lisp implementations can use American spelling, without 'and'):
numnames([two,hundred,and,thirty,six], 236).
numnames([two,hundred,and,thirty,seven], 237).
numnames([two,hundred,and,thirty,eight], 238).
numnames([two,hundred,and,thirty,nine], 239).
numnames([two,hundred,and,forty], 240).
numnames([two,hundred,and,forty,one], 241).
numnames([two,hundred,and,forty,two], 242).
numnames([two,hundred,and,forty,three], 243).
numnames([two,hundred,and,forty,four], 244).
numnames([two,hundred,and,forty,five], 245).
numnames([two,hundred,and,forty,six], 246).
numnames([two,hundred,and,forty,seven], 247).
numnames([two,hundred,and,forty,eight], 248).
numnames([two,hundred,and,forty,nine], 249).
numnames([two,hundred,and,fifty], 250).
I will report a well thought DCG solution proposed by Ken Johnson. Full code is here, with a small modification to make it usable (I tested in SWI-Prolog). I amended rules like ten_to_nine{*filter*}(13) --> [thir{*filter*}]. that sincerely I don't know how to handle.
:- module(dcg_numerals, [number//1]).
% Grammar for numbers, e.g.
% phrase(number(I),[two,hundred,and,fifty,six]).
% An astonishing characteristic of this code is that it's
% fully bidirectional. The expression
% phrase(number(256),Words)
% will instantiate Words = [two,hundred,and,fifty,six].
% What's more,
% phrase(number(I),Words)
% will eventually instantiate I and Words to all the numbers it knows.
%
% Ken Johnson 17-9-87
number(I) --> '1_to_999'(I).
number(I) --> '1000_to_999999'(I).
'1_to_999'(I) --> '1_to_99'(I).
'1_to_999'(I) --> '100_to_999'(I).
% Compound number with thousands
'1000_to_999999'(I) --> thousands(I).
'1000_to_999999'(I) --> thousands(K),'100_to_999'(Htu),
{
I is K + Htu
}.
'1000_to_999999'(I) --> thousands(K),[and],'1_to_99'(Tu),
{
I is K + Tu
}.
% Thousands
thousands(I) --> '1_to_999'(K), [thousand],
{
I is K * 1000
}.
% Compound number with hundreds, tens and units
'100_to_999'(C) --> one_to_nine(H),[hundred],
{
C is 100 * H
}.
'100_to_999'(C) --> one_to_nine(H),[hundred],[and],'1_to_99'(Tu),
{
C is (100 * H) + Tu
}.
% Complete number: a single word 1-9 or 10-19
'1_to_99'(I) --> one_to_nine(I).
% '1_to_99'(I) --> ten_to_nine{*filter*}(I).
'1_to_99'(I) --> ten_to_nine(I).
'1_to_99'(I) --> multiple_of_ten(I).
'1_to_99'(I) --> '20_to_99'(I).
% Compound number with tens and units
'20_to_99'(I) --> multiple_of_ten(T), one_to_nine(U),
{
I is T + U
}.
% Single words (terminal nodes)
one_to_nine(1) --> [one].
one_to_nine(2) --> [two].
one_to_nine(3) --> [three].
one_to_nine(4) --> [four].
one_to_nine(5) --> [five].
one_to_nine(6) --> [six].
one_to_nine(7) --> [seven].
one_to_nine(8) --> [eight].
one_to_nine(9) --> [nine].
/*
ten_to_nine{*filter*}(10) --> [ten].
ten_to_nine{*filter*}(11) --> [eleven].
ten_to_nine{*filter*}(12) --> [twelve].
ten_to_nine{*filter*}(13) --> [thir{*filter*}].
ten_to_nine{*filter*}(14) --> [four{*filter*}].
ten_to_nine{*filter*}(15) --> [fif{*filter*}].
ten_to_nine{*filter*}(16) --> [six{*filter*}].
ten_to_nine{*filter*}(17) --> [seven{*filter*}].
ten_to_nine{*filter*}(18) --> [eigh{*filter*}].
ten_to_nine{*filter*}(19) --> [nine{*filter*}].
*/
ten_to_nine(10) --> [ten].
ten_to_nine(11) --> [eleven].
ten_to_nine(12) --> [twelve].
ten_to_nine(13) --> [thirteen].
ten_to_nine(14) --> [fourteen].
ten_to_nine(15) --> [fifteen].
ten_to_nine(16) --> [sixteen].
ten_to_nine(17) --> [seventeen].
ten_to_nine(18) --> [eighteen].
ten_to_nine(19) --> [nineteen].
multiple_of_ten(20) --> [twenty].
multiple_of_ten(30) --> [thirty].
multiple_of_ten(40) --> [forty].
multiple_of_ten(50) --> [fifty].
multiple_of_ten(60) --> [sixty].
multiple_of_ten(70) --> [seventy].
multiple_of_ten(80) --> [eighty].
multiple_of_ten(90) --> [ninety].