I have a dictionary created from the DictionaryCreator from UIMA, I would like to annotate a piece of text using the DictionaryAnnotator and the aforementioned dictionary, I could not figure out how to get the annotated text. Please let me know if you do. Any help is appreciated. The code, the dictionary-file and the descriptor is mentioned below,
P.S. I'm new to Apache UIMA.
XMLInputSource xml_in = new XMLInputSource("DictionaryAnnotatorDescriptor.xml");
ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xml_in);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
JCas jCas = ae.newJCas();
String inputText = "Mark and John went down the rabbit hole to meet a wise owl and have curry with the owl.";
jCas.setDocumentText(inputText);
printResults(jCas);
public static void printResults(JCas jcas) {
FSIndex<Annotation> index = jcas.getAnnotationIndex();
for (Iterator<Annotation> it = index.iterator(); it.hasNext(); ) {
Annotation annotation = it.next();
List<Feature> features;
features = annotation.getType().getFeatures();
List<String> fasl = new ArrayList<String>();
for (Feature feature : features) {
try {
String name = feature.getShortName();
System.out.println(feature.getName());
String value = annotation.getStringValue(feature);
fasl.add(name + "=\"" + value + "\"");
System.out.println(value);
}catch (Exception e){
continue;
}
}
}
}
my_dictionary.xml
<?xml version="1.0" encoding="UTF-8"?>
<dictionary xmlns="http://incubator.apache.org/uima" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="dictionary.xsd">
<typeCollection>
<dictionaryMetaData caseNormalization="true" multiWordEntries="true" multiWordSeparator=" "/>
<languageId>en</languageId>
<typeDescription>
<typeName>org.apache.uima.DictionaryEntry</typeName>
</typeDescription>
<entries>
<entry>
<key>Mark</key>
</entry>
<entry>
<key>John</key>
</entry>
<entry>
<key>Rabbit</key>
</entry>
<entry>
<key>Owl</key>
</entry>
<entry>
<key>Curry</key>
</entry>
<entry>
<key>ATH-MX50</key>
</entry>
<entry>
<key>CC234</key>
</entry>
</entries>
</typeCollection>
</dictionary>
DictionaryAnnotatorDescriptor.xml
<?xml version="1.0" encoding="UTF-8"?>
<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
<frameworkImplementation>org.apache.uima.java</frameworkImplementation>
<primitive>true</primitive>
<annotatorImplementationName>org.apache.uima.annotator.dict_annot.impl.DictionaryAnnotator</annotatorImplementationName>
<analysisEngineMetaData>
<name>GeneDictionaryAnnotator</name>
<description></description>
<version>0.1</version>
<vendor></vendor>
<configurationParameters>
<configurationParameter>
<name>DictionaryFiles</name>
<description>list of dictionary files to configure the annotator</description>
<type>String</type>
<multiValued>true</multiValued>
<mandatory>true</mandatory>
</configurationParameter>
<configurationParameter>
<name>InputMatchType</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>true</mandatory>
</configurationParameter>
<configurationParameter>
<name>InputMatchFeaturePath</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>false</mandatory>
</configurationParameter>
<configurationParameter>
<name>InputMatchFilterFeaturePath</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>false</mandatory>
</configurationParameter>
<configurationParameter>
<name>FilterConditionOperator</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>false</mandatory>
</configurationParameter>
<configurationParameter>
<name>FilterConditionValue</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>false</mandatory>
</configurationParameter>
</configurationParameters>
<configurationParameterSettings>
<nameValuePair>
<name>DictionaryFiles</name>
<value>
<array>
<string>src/main/resources/my_dictionary.xml</string>
</array>
</value>
</nameValuePair>
<nameValuePair>
<name>InputMatchType</name>
<value>
<string>org.apache.uima.TokenAnnotation</string>
</value>
</nameValuePair>
</configurationParameterSettings>
<typeSystemDescription>
<types>
<typeDescription>
<name>org.apache.uima.DictionaryEntry</name>
<description></description>
<supertypeName>uima.tcas.Annotation</supertypeName>
</typeDescription>
<typeDescription>
<name>org.apache.uima.TokenAnnotation</name>
<description>Single token annotation</description>
<supertypeName>uima.tcas.Annotation</supertypeName>
<features>
<featureDescription>
<name>tokenType</name>
<description>token type</description>
<rangeTypeName>uima.cas.String</rangeTypeName>
</featureDescription>
</features>
</typeDescription>
<typeDescription>
<name>example.Name</name>
<description>A proper name.</description>
<supertypeName>uima.tcas.Annotation</supertypeName>
</typeDescription>
</types>
</typeSystemDescription>
<capabilities>
<capability>
<inputs/>
<outputs>
<type>example.Name</type>
</outputs>
<languagesSupported/>
</capability>
</capabilities>
<operationalProperties>
<modifiesCas>true</modifiesCas>
<multipleDeploymentAllowed>true</multipleDeploymentAllowed>
<outputsNewCASes>false</outputsNewCASes>
</operationalProperties>
</analysisEngineMetaData>
</analysisEngineDescription>
Alternatively, you could also use Apache Ruta, either with the workbench (recommended to get started) or with java code.
For the latter, I created an example project at https://github.com/renaud/annotate_ruta_example. The main parts are:
a list of names in src/main/resources/ruta/resources/names.txt (a plain text file)
Mark
John
Rabbit
Owl
Curry
ATH-MX50
CC234
a Ruta script in src/main/resources/ruta/scripts/Example.ruta
PACKAGE example.annotate; // optional package def
WORDLIST MyNames = 'names.txt'; // declare dictionary location
DECLARE Name; // declare an annotation
Document{-> MARKFAST(Name, MyNames)}; // annotate document
and some java boilerplate code to launch the annotator:
JCas jCas = JCasFactory.createJCas();
// the sample text to annotate
jCas.setDocumentText("Mark wants to buy CC234.");
// configure the engine with scripts and resources
AnalysisEngine rutaEngine = AnalysisEngineFactory.createEngine(
RutaEngine.class, //
RutaEngine.PARAM_RESOURCE_PATHS,
"src/main/resources/ruta/resources",//
RutaEngine.PARAM_SCRIPT_PATHS,
"src/main/resources/ruta/scripts",
RutaEngine.PARAM_MAIN_SCRIPT, "Example");
// run the script. instead of a jCas, you could also provide a UIMA collection reader to process many documents
SimplePipeline.runPipeline(jCas, rutaEngine);
// a simple select to print the matched Names
for (Name name : JCasUtil.select(jCas, Name.class)) {
System.out.println(name.getCoveredText());
}
there is also some UIMA type (annotation) definitions, check src/main/resources/desc/type/ExampleTypes.xml, src/main/resources/META-INF/org.apache.uima.fit/types.txt and src/main/java/example/annotate.
how to test it
git clone https://github.com/renaud/annotate_ruta_example.git
cd annotate_ruta_example
mvn clean install
mvn exec:java -Dexec.mainClass="example.Annotate"
Related
I have searched for this in Internet but unable to find a answer.
I am new to SOAP services, If I am wrong at any point please correct me. I was trying to generate Java classes from wsdl using command line tool ** JAX-WS RI wsimport**. I was able to generate all Request and Response classes.
The ObjectFactory.java generated from wsdl was missing most of the methods.
employee.wsdl.jaxb.bnd.xml
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb/xjc">
<jaxb:bindings>
<jaxb:globalBindings generateElementProperty="false">
<xjc:serializable>
</jaxb:globalBindings>
</jaxb:bindings>
</jaxb:bindings>
employee.wsdl.bnd.xml
<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://java.sun.com/xml/ns/jaxws"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
wsdlLocation="../sp.wsdl">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
In jaxb.bnd.xml
While trying with <jaxb:globalBindings generateElementProperty="true"> Its able to generate all of the factory methods. But it was using JAXBElement<> wrapper for primititve data types like String,int,Long
While trying with <jaxb:globalBindings generateElementProperty="fasle"> Its able to generate the class without JAXBElement<> wrapper, but missing most of the factory methods.
cmd: wsimport META-INF/wsdl/employee.wsdl -keep -b META-INF/wsdl/bindings/employee.bnd.xml -b META-INF/wsdl/bindings/employee.jaxb.bnd.xml -wsdllocation META-INF/wsdl/employee.wsdl
Sample ObjectFactory.java
package xyz;
#XmlRegistry
class ObjectFactory {
private final static Qname _EmpDetailsSpecialEmpDetail_QNAME = new QName("", "scheduleEmp");
#XmlElementDecl(namespce = "", name="specialEmployee", scope= EmpDetails.class)
public SpecialEmpDetail EmpDetailsSpecialEmployee(SpecialEmpDetail value) {
return new SpecialEmpDetail(_EmpDetailsSpecialEmpDetail_QNAME, SpecialEmpDetail.class, EmpDetail.class, value);
}
EmpDetail.java
public class EmpDetail implements Serializable {
#XmlElementRef(name= "specialEmployee", required=false)
protected SpecialEmpDetail specialEmployee;
public SpcialEmpDetail getSpecialEmployee() {
return specialEmployee;
}
public SpcialEmpDetail setSpecialEmployee(SpcialEmpDetail value) {
this.specialEmployee = value;
}
}
SpecialEmpDetail.java
public class SpecialEmpDetail {
//local var
//getter and setter
.....
}
employee.wsdl
<?xml version="1.0" encoding="UTF-8">
<definitions name="psp"
targetNamespace="http://www.namespace.com/employee.wsdl"
.....
/>
<types>
<schmea targerNamespace = "http://www.namespace.com/employee.wsdl"
xmlns:SOAP-ENV = "http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi = "http://www.w3.org/2003/05/XMLSchema-instance"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
xmlns:emp = "http://www.namespace.com/employee/employee.xsd1"
<import namespace="http://www.namespace.com/employee.xsd1"/>
<import namespace="http://www.w3.org/2003/05/soap-encoding"/>
</schmea>
<schmea targerNamespace = "http://www.namespace.com/employee.xsd1"
xmlns:SOAP-ENV = "http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi = "http://www.w3.org/2003/05/XMLSchema-instance"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
xmlns:emp = "http://www.namespace.com/employee/employee.xsd1"
<import namespace="http://www.namespace.com/employee.wsdl"/>
<import namespace="http://www.w3.org/2003/05/soap-encoding"/>
<simpleType name="empName">
<restrictions base="xsd:string">
<minLength value="1"/>
<maxLength value="30"/>
</restrictions>
<simpleType name="EmpID">
<restrictions base="xsd:string">
<minLength value="0"/>
<maxLength value="25"/>
</restrictions>
</simpleType>
<complexType name="">
<sequence>
<element name="specialEmployee" type="emp:SpecialEmpDetail minOccurs="0" maxOccurs="1" />
</sequence>
</complexType>
.....
.........
</schema>
</types>
Here is the sample wsdl and java. I can able to generate SpecialEmpDetail.java & EmpDetail.java The ObjectFctory.java should create the mentioned function, but its failed to do so.... Using JAXBElement<> wrapper I can able to generate all functions but the problem here is its a complextType data so wrapping is fine, But String also wrapped this is not expected.
What may be problem?? How can I resolve it??
Thanks in Advance!
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xml>
<Settings version="3" xmlns="urn:Adapter-v3">
<Connections>
<Connection name ="A" description="DEV">
<SaveVersion version="M" siteURL="https://example.com" />
<Save>
<Id>id123</Id>
<Client>hello</Client>
</Save>
</Connection>
<Connection name ="B" description="DEV1">
<SaveVersion version="M" siteURL="https://example.com" />
<Auth>
<UserId>id123</UserId>
<Password>pass</Password>
</Auth>
</Connection>
</Connections>
<Mappings>
<Mapping cont="AA" auction="A1">
<Description>Desc</Description>
<Content
attr1="IO"
attr2="d"
attr3="Information"
attr4="false"
<Element enabled="false" count="200" prefix="DocLib_" itemPrefix="0" />
<Sub enabled="false" count="100" prefix="Folder_" itemPrefix="0" />
<FilenameA auction="N" delay="3" />
</Content>
</Mapping>
<Mapping cont="AB" auction="SharePointOLDev1">
<Description>Desc</Description>
<Content
attr1="IO"
attr2="d"
attr3="Information"
attr4="false"
<Element enabled="false" count="200" prefix="DocLib_" itemPrefix="0" />
<Sub enabled="false" count="100" prefix="1" itemPrefix="0" />
</Content>
</Mapping>
</Mappings>
<TypeMappings>
<TypeMapping Type="rfid" ext="msg" />
</TypeMappings>
</Settings>
Trying to unmarshal the above xml file to java objects.
Generated Settings.java and ObjectFactory.java file using xjc tool.These files are deployed in the src folder(along with other java files.)
WHen i unmarshal i get null valuues for Connections,Mappings and TypeMappings.
Is there any steps that i am missing?
public class JAXBImpl{
public static void main(String args[]){
JAXBContext jaxbContext;
Settings que= null;
jaxbContext = JAXBContext.newInstance(Settings.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
que= (Settings) jaxbUnmarshaller.unmarshal(file);
System.out.println(que.getConnections().getConnection());
}
}
I'm trying to add a new line of tag "" with different attributes. I'm able to edit an existing line but not able to add new tag having different attributes.
The XML file
<elementDefinitionPackage elementDefinitionPackageName="kohler-decisionmaker" elementDefinitionPackageVersion="3.2.0.42" elementLibraryFilename="libkohler-decisionmaker.so" elementLibraryVersion="3.2.0.42" minSupportedGDDVersion="1.0" minSupportedUMGFirmwareVersion="1.1.0.0" xmlns="http://xmlns.commonplatform.avocent.com/mss/ddt/template" xmlns:cm="http://xmlns.commonplatform.avocent.com/mss/ddt/common" xmlns:r="http://xmlns.commonplatform.avocent.com/mss/ddt/rules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.commonplatform.avocent.com/mss/ddt/template XSD_ddt.xsd http://xmlns.commonplatform.avocent.com/mss/ddt/rules XSD_rules.xsd http://xmlns.commonplatform.avocent.com/mss/ddt/common XSD_common.xsd">
<elementDefinitionModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="DEC4000" modelQualifierInSymbol="DEC4000" symbolTag="KOHLERDEC4000DEC4000">
<supportedprotocols>
<supportedProtocol isSubscribable="false" protocolName="MODBUS/RS-485">
<properties>
<property category="EXTCOMM" defaultValue="502" definition="PORT" valueType="Integer" />
<property category="EXTCOMM" defaultValue="60" definition="TIMEOUT" valueType="Integer" />
<property category="EXTCOMM" defaultValue="1" definition="SLAVEID" valueType="Integer"/>
</properties>
<datapoints>
<datapoint division="COLL_COMP_CEP" nature="PARAMETRIC" programmaticName="t_val_calc_enrg_interval"/>
</datapoints>
<events>
<event address="3.{SLAVEID}.40259.1" programmaticName="t_evt_gen_mainTankAlarm" values="a:1 i:0" />
</events>
<commands>
<command access="RW" address="#RWDA 3.{SLAVEID}.61105 6.{SLAVEID}.61105" division="CONTROL" nature="ENUM" programmaticName="t_st_gen_setControl" valueTypeInDevice="DATA_POINT_VALUE_TYPE_INTEGER" />
</commands>
</supportedProtocol>
</supportedprotocols>
<rules>
</rules>
<similarModels>
<similarModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="KD440" modelQualifierInSymbol="KD440" symbolTag="KOHLERKD440KD440"/>
</similarModels>
</elementDefinitionModel>
Expected Output XML file
<elementDefinitionPackage elementDefinitionPackageName="kohler-decisionmaker" elementDefinitionPackageVersion="3.2.0.42" elementLibraryFilename="libkohler-decisionmaker.so" elementLibraryVersion="3.2.0.42" minSupportedGDDVersion="1.0" minSupportedUMGFirmwareVersion="1.1.0.0" xmlns="http://xmlns.commonplatform.avocent.com/mss/ddt/template" xmlns:cm="http://xmlns.commonplatform.avocent.com/mss/ddt/common" xmlns:r="http://xmlns.commonplatform.avocent.com/mss/ddt/rules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.commonplatform.avocent.com/mss/ddt/template XSD_ddt.xsd http://xmlns.commonplatform.avocent.com/mss/ddt/rules XSD_rules.xsd http://xmlns.commonplatform.avocent.com/mss/ddt/common XSD_common.xsd">
<elementDefinitionModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="DEC4000" modelQualifierInSymbol="DEC4000" symbolTag="KOHLERDEC4000DEC4000">
<supportedprotocols>
<supportedProtocol isSubscribable="false" protocolName="MODBUS/RS-485">
<properties>
<property category="EXTCOMM" defaultValue="502" definition="PORT" valueType="Integer" />
<property category="EXTCOMM" defaultValue="60" definition="TIMEOUT" valueType="Integer" />
<property category="EXTCOMM" defaultValue="1" definition="SLAVEID" valueType="Integer"/>
</properties>
<datapoints>
<datapoint division="COLL_COMP_CEP" nature="PARAMETRIC" programmaticName="t_val_calc_enrg_interval"/>
</datapoints>
<events>
<event address="3.{SLAVEID}.40259.1" programmaticName="t_evt_gen_mainTankAlarm" values="a:1 i:0" />
</events>
<commands>
<command access="RW" address="#RWDA 3.{SLAVEID}.61105 6.{SLAVEID}.61105" division="CONTROL" nature="ENUM" programmaticName="t_st_gen_setControl" valueTypeInDevice="DATA_POINT_VALUE_TYPE_INTEGER" />
</commands>
</supportedProtocol>
</supportedprotocols>
<rules>
</rules>
<similarModels>
<similarModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="KD440" modelQualifierInSymbol="KD440" symbolTag="KOHLERKD440KD440"/>
<similarModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="A" modelQualifierInSymbol="B" symbolTag="C"/>
</similarModels>
</elementDefinitionModel>
Java Code
private static void updat() {
NodeList similarmodels = doc.getElementsByTagName("similarModels");
Element model = null;
for(int i=0; i<similarmodels.getLength();i++){
model = (Element) similarmodels.item(i);
String model = model.getElementsByTagName("similarModel").item(0).getFirstChild().getNodeValue();
if(model.equalsIgnoreCase("KD440")){
model.setAttribute("A");
}else{
model.setAttribute("B");
}
}
}
Is there a way of doing this in JAXB & xsd??
Should be no problem, neither with DOM nor with JAXB. In JAXB you should simply be able to create a new SimilarModel object which you then can add in the SimilarModels object's list.
Is it possible:
Class Qwe {
#SuperAdapter
Map<String, String> prms
}
after marshalling:
<qwe>
<prms>
<prm>
<name>qwe</name>
<val>zxc</val>
</prm>
<prm>
<name>tyu</name>
<val>ghj</val>
</prm>
...
</prms>
</qwe>
I can solve this problem if I have access to the DOM or insert ram xml part.
Or advise me the best solution.
I can solve it via subclasses but I do not think that is a good solution.
Please see this post by Blaise Doughan. Snippets:
package blog.map;
import java.util.*;
import javax.xml.bind.annotation.*;
#XmlRootElement
public class Customer {
private Map<String, Address> addressMap = new HashMap<String, Address>();
#XmlElementWrapper(name="addresses")
public Map<String, Address> getAddressMap() {
return addressMap;
}
public void setAddressMap(Map<String, Address> addressMap) {
this.addressMap = addressMap;
}
}
Output:
<?xml version="1.0" encoding="UTF-8"?>
<customer>
<addresses>
<entry>
<key>shipping</key>
<value>
<street>2 B Road</street>
</value>
</entry>
<entry>
<key>billing</key>
<value>
<street>1 A Street</street>
</value>
</entry>
</addresses>
</customer>
In my Flex Application MXML file i'm writing..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
width="598" height="459" creationComplete="consumer.subscribe()" layout="vertical">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.messaging.messages.AsyncMessage;
import mx.messaging.messages.IMessage;
public function send():void {
var message:IMessage = new AsyncMessage();
message.destination = "SimpleChatDestination";
message.body = "\n" + usernameInput.text + ":\t" + messageInput.text;
trace(producer.connected);
producer.send(message);
messageInput.text = "";
}
public function messageHandler( message:IMessage ):void {
textArea.text += message.body;
}
]]>
</mx:Script>
<mx:Producer id="producer" destination="SimpleChatDestination"/>
<mx:Consumer id="consumer" destination="SimpleChatDestination" message="messageHandler(event.message)"/>
<mx:TextArea id="textArea" width="400" height="300" color="#F31C1C" editable="false"
enabled="false"/>
<mx:HBox horizontalGap="0">
<mx:TextInput id="usernameInput" width="80"/>
<mx:TextInput id="messageInput" width="180"/>
<mx:Button label="Send" click="send();"/>
</mx:HBox>
</mx:Application>
And in BlazeDs(java side) message-config.xml file i wrote code like this.
<?xml version="1.0" encoding="UTF-8"?>
<service id="message-service"
class="flex.messaging.services.MessageService">
<adapters>
<adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
<!-- <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/> -->
</adapters>
<default-channels>
<channel ref="my-polling-amf"/>
</default-channels>
<adapters>
<adapter-definition id="actionscript" default="true" />
<!-- <adapter-definition id="jms"/> -->
</adapters>
<default-channels>
<channel ref="my-polling-amf"/>
</default-channels>
<destination id="SimpleChatDestination">
<properties>
<network>
<subscription-timeout-minutes>0</subscription-timeout-minutes>
</network>
<server>
<message-time-to-live>0</message-time-to-live>
<allow-subtopics>true</allow-subtopics>
<subtopic-separator>.</subtopic-separator>
</server>
</properties>
</destination>
</service>
So it is Working fine. But problem is when ever we open three are four chat boxes then all chat boxes are participated.
i want only allow two user can only chat if 3rd user came not visiable 2nd person chating information.
just it is like Facebook,Gmail chating.
plz help me..