trigram and prevtwomap feature generator in xml descriptor - opennlp

I am using OpenNLP NameFinder. It allows us to define feature generators for entities like this (taken from here):
<generators>
<cache>
<generators>
<window prevLength = "2" nextLength = "2">
<tokenclass/>
</window>
<window prevLength = "2" nextLength = "2">
<token/>
</window>
<definition/>
<prevmap/>
<bigram/>
<sentence begin="true" end="false"/>
</generators>
</cache>
</generators>
But I am unable to find XML feature generator for TrigramFeatureGenerator and PrevTwoMapFeatureGenerator. I tried and but it showing InvalidFormatException. Can anyone tell me xml descriptor for Trigram and PrevTwoMap feature generator?

I did not find any standard xml descriptor for TrigramNameFeatureGenertor and PreviousTwoMapFeatureGenerator but I figured out a way. I registered trigram and prevtwomap as custom xml descriptor which points to their respective java classes.

Related

Update parameter value in XML format

I have parameters stored in an XML file. Below is a sample of the file.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<terminal id="A">
<terminalCapacity>3</terminalCapacity>
<terminalMembers id="1">
<memberID>0001</memberID>
<memberCapacity>2</memberCapacity>
</terminalMembers>
</terminal>
<terminal id="B">
<terminalCapacity>4</terminalCapacity>
<terminalMembers id="1">
<memberID>0002</memberID>
<memberCapacity>1</memberCapacity>
</terminalMembers>
<terminalMembers id="2">
<memberID>0003</memberID>
<memberCapacity>3</memberCapacity>
</terminalMembers>
</terminal>
</root>
Each terminalID is associated to a type of simpleModule found in my NED file. The idea is to programmatically update these values throughout the simulation run. The current logic revolves around getting the current parameters in XML format and update the memberCapacity field.
From the Omnet cPar and cXMLElement documentation, I tried using the par("moduleParameter").xmlValue()->getXML() function, but this returns the XML as a string. I also tried using the getAttribute() function, but to no success.
Don't do this. par("moduleParameter").xmlValue() will give you the in memory object tree of the XML document, but that is not meant for modification. Your XML file seems to be just a hierarchical structure and modules and their parameters can mirror that exactly. There is absolutely no reason to reinvent the wheel when you can mirror that with INI file parameters.

How can I generate attributes with obj2xml for ruby classes generated from xsd2ruby?

I've used the utility xsd2ruby utility provided with soap4r to generate the required classes from an XSD schema definition file. This works well, however when I try to generate an xml file using XSD::Mapping.obj2xml the attributes do not get created as I expect (or would like). I would like the following:
<obj attr1=value1 attr2=value2>
<element1>value</element1>
</obj>
but this is what gets generated:
<obj>
<__xmlattr>
<item>
<key>
<name>attr1</name>
<namespace></namespace>
<source></source>
</key>
<value>value1</value>
</item>
<item>
<key>
<name>attr2</name>
<namespace></namespace>
<source></source>
</key>
<value>value2</value>
</item>
</__xmlattr>
<element1>value</element1>
</obj>
How can I generate the XML output without the xmlattr?
From what I remember XSD::Mapping.obj2xml XML will use an instance's instance variables as element names and their values as child elements. That's all. With the instance variable #__xmlattr getting special processing, as you can see.
To get around these limitations I wrote jaxb2ruby. It generates classes based on an ERB template. You can use one of the builtin templates (ROXML, HappyMapper, or plain ruby class) or write your own.
It's not perfect but has worked out well for me in several instances.
You may also want to checkout ROAR.

With mybatis-spring and MapperScannerConfigurer reuse resultMap in multiple Mapper xml files

We are using
mybatis-spring = 1.1.1
mybatis = 3.1.1
spring = 3.2.0
MapperScannerConfigurer - to scan mappers
How do we reuse resultMap in multiple Mapper xml files?
In this answered question "Reusing MyBatis ResultMap in multiple mapper.xml"
Solution is to use mybatis-config.xml files and add resultMap detail in that file (or import all mapper files in that file).
But we are not using that file and instead using mybatis-spring's MapperScannerConfigurer.
So how can we achieve the same feature with MapperScannerConfigurer?
For example we have a userMapper.xml.
<resultMap id="user" type="com.domain.ModelUser">
<result>..</result>
...
...
</resultMap>
and we need to use this resultMap in for example managerMapper.xml
and need to reuse the "user" resultMap.
For example
<select id="getManager" resultMap="com.domain.ModelUser.user">
select .......
</select>
Right now it throws error
java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.domain.ModelUser.user
As of now it do not know how and where to find the resultMap in UserMapper.xml file
Any help and direction toward it will be appreciated.
Thank you for you time and help.
You can still use mybatis-config.xml even with Spring and the MapperScanner. This xml file does not have to be a complete (or valid) configuration for base MyBatis. Just create a simple config like this:
<config>
<mapper namespace="foo">
<resultMap id="user" type="com.domain.ModelUser">
<result>..</result>
...
...
</resultMap>
</mapper>
</config>
Reference this file with SqlSessionFactoryBean.setConfigLocation(). It will get loaded when the SqlSessionFactory is created and will be accessible using the namespace provided.
I know it's late but I was also getting similar exception in one of my project. Use id of the resultMap in your getManager query as shown below:
<select id="getManager" resultMap="user">
select .......
</select>

How to move property value from Properties file to payload object using spring integration elements

Sample.properties
=================
http.header.amisys.accept.value=arun/vnd.dsths.services-v1+xml
1)Above XSL automatically loaded when my server starts.
2)I have tried <int:enricher> element but it is not helped me.
Sample Code : Below is bit of code I have tried, Can any one suggest me on this.
<int:channel id="PQLegacySecurity-InputChannel" />
<int:chain input-channel="PQLegacySecurity-InputChannel" >
<!-- Split the Search Request Params from Xml -->
<int-xml:xpath-splitter>
<int-xml:xpath-expression expression="//LegacySecurity" namespace map="xmlMessageNamespace" />
</int-xml:xpath-splitter>
<int:enricher >
<int:payload name="testPayload" expression="${http.header.amisys.accept.value}"/>
</int:enricher>
</int:chain>
Actual Payload Object:Below is the xml which does not contain testPayload property.
<?xml version="1.0" encoding="UTF-8"?><LegacySecurity>
<businessArea>%%%%%%</businessArea>
<LegacySystem>%%%%%</LegacySystem>
<LegacyUserID>%%%%%</LegacyUserID>
<LegacyPassword>%%%%%</LegacyPassword>
<OtherLogin/>
<OtherPassword/>
<AddSecurLogin/>
<AddSecurPassword/>
</LegacySecurity>
Expected Payload Object: Below Object contains new element testPayload node which I should able to add
<?xml version="1.0" encoding="UTF-8"?><LegacySecurity>
<businessArea>%%%%%%</businessArea>
<LegacySystem>%%%%%</LegacySystem>
<LegacyUserID>%%%%%</LegacyUserID>
<LegacyPassword>%%%%%</LegacyPassword>
<OtherLogin/>
<OtherPassword/>
**<testPayload>arun/vnd.dsths.services-v1+xml</testPayload>**
<AddSecurLogin/>
<AddSecurPassword/>
</LegacySecurity>
You can use an xslt transformer. Something like the below, though you will need to figure out correct use of the transformer from the spring docs.
Notice you can pass a parameter through to the XSLT
<int-xml:xslt-transformer result-transformer="toDocumentTransformer" result-type="StringResult" xsl-resource="/xslt/addTestPayload.xslt">
<int-xml:xslt-param name="testPayload" value="${http.header.amisys.accept.value}"/>
</int-xml:xslt-transformer>
In the XSLT file, use this to pick up the parameter:
<xsl:param name="testPayload" />
If you have other changes you need to make to the message you can use the same xslt.

How to access jcr:root with XPath JCR Query

I would like to apply some java function on CQ5 dialogs. In the first step I search for dialog xml files in myComponent folder as follow:
NodeIterator tabRequiredFields = getQueryResult("/jcr:root/apps/myProject/pages/myComponent/dialog/jcr:root")
But this Query does not supply any results. crx Xpath tool does not show any result too see the follwoing picture:
my /jcr:root/apps/myProject/pages/myComponent/dialog.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Dialog"
stateful="false"
title="Test"
.....>
<items
jcr:primaryType="cq:Widget"
xtype="panel">
...
......
</items>
.....
</jcr:root>
I can access items as follow
NodeIterator tabRequiredFields = getQueryResult("/jcr:root/apps/myProject/pages/myComponent/dialog/items")
This works fine. My Question is: why for jcr:root? how to check, if jcr:root exists?
XML element named jcr:root from the dialog.xml doesn't create jcr:root node in the repository. It's a special, reserved identifier and CRX Package Manager puts all properties and subnodes of this element into a node which name is the same as name of the file without extension (in your case it'll be dialog).
If it's not clear, use CRX DE, open /apps/myProject/pages/myComponent and see what you can find there. That's why you should add /dialog rather than /jcr:root to the end of your path.
If you want to find all dialogs, use the primary type cq:Dialog, as rakhi4110 suggests. Following query:
/jcr:root/apps/myProject/pages//element(*, cq:Dialog)
will return all dialogs from /apps/myProject/pages (and descendants).

Resources