This questions describes how to reuse a pipeline in dkpro but if I only create one JCas and then try to change the text then I get the exception
org.apache.uima.cas.CASRuntimeException: Data for Sofa feature setLocalSofaData() has already been set.
How do I get around this?
The sofa data in the CAS can only be set once. It cannot be modified after it has been set.
In order to re-use a CAS, call the reset() method on it. This clears all annotations and allows you to set the sofa/text again.
To build a CAS incrementally, a common strategies is to add annotations to the CAS while adding text to a string buffer and setting the text only at the end of the process.
An uimaFIT-based example could look something like this:
Strings[] texts = {
"Hello world.",
"This is a test." };
// Create empty CAS/JCas initialized using uimaFIT typesystem auto-detection
JCas jcas = JCasFactory.createJCas();
// Instantiate some analysis engine
AnalysisEngine engine = AnalysisEngineFactory.createEngine(...);
// Process texts re-using the previously created CAS/JCas instance
for (String t : texts) {
jcas.reset();
jcas.setDocumentText(t);
jcas.setDocumentLanguage("en");
engine.process(jcas);
}
engine.collectionProcessComplete();
engine.destroy();
Disclosure: I am working on the Apache UIMA project.
Related
I have a form fields binded to java entity model. That model has an annotation:
#ValidPassword
private String password
which validates the field with some conditions and return error message containing each failed condition separated by '\n' new line sign.
Vaadin form is connected to this model with:
username = new TextField("Username");
username.addClassName("username-field");
password = new PasswordField("Password");
password.addClassName("password-field");
binder.forField(username ).asRequired().bind("username");
binder.forField(password).asRequired().bind("password");
Writting input to password field results in:
image-link
When I want each failed condition to start on a new line.
If you want to use JSR-303 Bean validation with Vaadin 8 or like Vaadin 14 and newer, then you need to use BeanValidationBinder instead of regular Binder. Also in that case you are not supposed to build bindings using
binder.forField(password).asRequired().bind("password");
But instead just use
binder.bindInstanceFields(form);
Furthermore, if you need to customize how error is being displayed, you can use for example ValidationStatusHandler, which is called each time validation status changes from valid to invalid or vica versa. By default the error is shown inlined in component. You can define your own component, e.g. Html, where you can use rich formatting.
binder.forField(field).withValidationStatusHandler(handler -> {
if (handler.isError()) {
handler.getMessage().ifPresent(error -> {
Html html = new Html("<span>"+error+"</span>");
layout.add(html);
});
}
}).bind("property");
I have a C# application that performs mail merges with MS Office (using Interop API).
I am now trying to have it support Open office.
I want to use OpenOffice SDK:
http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/MailMerge.html#Command
Does not look crystal clear to me right now....
I somehow managed to get the mail merge code to work.
The thing is we need to create a "DataSource" before actually performing the MailMerge and I encounter difficulties to do it.
I can get a sample in Java here:
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Database/The_DataSource_Service
I would need to convert this into C#.
My difficulty is that Java uses this object to perform its casts:
XStorable store = ( XStorable)UnoRuntime.queryInterface(XStorable.class, xDs);
There is nothing equivalent in C#.
I converted the code this way:
public static void CreateDataSource(string dataSourceProvidedFilePath, string dataSourceSavedFilePath)
{
XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory _rMSF = (XMultiServiceFactory)oStrap.getServiceManager();
// the XSingleServiceFactory of the database context creates new generic
// com.sun.star.sdb.DataSources (!)
// retrieve the database context at the global service manager and get its
// XSingleServiceFactory interface
XSingleServiceFactory xFac = (XSingleServiceFactory) _rMSF.createInstance("com.sun.star.sdb.DatabaseContext");
//(XSingleServiceFactory)UnoRuntime.queryInterface(XSingleServiceFactory.class, _rMSF.createInstance("com.sun.star.sdb.DatabaseContext"));
// instantiate an empty data source at the XSingleServiceFactory
// interface of the DatabaseContext
Object xDs = xFac.createInstance();
// register it with the database context
XNamingService xServ = (XNamingService)xFac;
//(XNamingService)UnoRuntime.queryInterface(XNamingService.class, xFac);
XStorable store = ( XStorable) xDs;
//( XStorable)UnoRuntime.queryInterface(XStorable.class, xDs);
XModel model =( XModel) xDs;
//( XModel)UnoRuntime.queryInterface(XModel.class, xDs);
//on détermine le fichier ou sera sauvegardée la data source
string dataSourcePathURL = Path.Combine(Path.GetDirectoryName(dataSourceProvidedFilePath), dataSourceSavedFilePath + ".odb").ConvertToOpenOfficeURL();
store.storeAsURL(/*"file:///c:/test.odb"*/dataSourcePathURL,model.getArgs());
xServ.registerObject("NewDataSourceName", xDs);
// setting the necessary data source properties
XPropertySet xDsProps = (XPropertySet)xDs;
//(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xDs);
// Adabas D URL
xDsProps.setPropertyValue("URL", new uno.Any("sdbc:adabas::MYDB1"));
// force password dialog
//xDsProps.setPropertyValue("IsPasswordRequired", new Boolean(true));
// suggest dsadmin as user name
xDsProps.setPropertyValue("User", new uno.Any("dsadmin"));
store.store();
}
Some casts worked fine:
XNamingService xServ = (XNamingService)xFac;
//(XNamingService)UnoRuntime.queryInterface(XNamingService.class, xFac);
But some other casts throw an exception:
XStorable store = ( XStorable) xDs;
//( XStorable)UnoRuntime.queryInterface(XStorable.class, xDs);
->
Unable to cast transparent proxy to type 'unoidl.com.sun.star.frame.XStorable'.
Is there a way to have this code correctly converted to C#?
Otherwise, do you know any other resource showing how to create an Open Office DataSource in Java?
Thx
First I tried using C# and encountered the same error you described.
Then I tried the example using Java and ended up with a null value for XStorable. So I think your problem is not due to C#, but because for some reason the empty data source is not getting created properly.
In Create a libreoffice text-based datasource and set settings with java, the poster seems to have had success, so I'm not sure what went wrong when I tried it.
This code to print data sources does work for me: https://wiki.openoffice.org/wiki/Documentation/DevGuide/Database/Data_Sources_in_OpenOffice.org_API.
Background
My application connects to the Genesys Interaction Server in order to receive events for actions performed on the Interaction Workspace. I am using the Platform SDK 8.5 for Java.
I make the connection to the Interaction Server using the method described in the API reference.
InteractionServerProtocol interactionServerProtocol =
new InteractionServerProtocol(
new Endpoint(
endpointName,
interactionServerHost,
interactionServerPort));
interactionServerProtocol.setClientType(InteractionClient.AgentApplication);
interactionServerProtocol.open();
Next, I need to register a listener for each Place I wish to receive events for.
RequestStartPlaceAgentStateReporting requestStartPlaceAgentStateReporting = RequestStartPlaceAgentStateReporting.create();
requestStartPlaceAgentStateReporting.setPlaceId("PlaceOfGold");
requestStartPlaceAgentStateReporting.setTenantId(101);
isProtocol.send(requestStartPlaceAgentStateReporting);
The way it is now, my application requires the user to manually specify each Place he wishes to observe. This requires him to know the names of all the Places, which he may not necessarily have [easy] access to.
Question
How do I programmatically obtain a list of Places available? Preferably from the Interaction Server to limit the number of connections needed.
There is a method you can use. If you check methods of applicationblocks you will see cfg and query objects. You can use it for get list of all DNs. When building query, try blank DBID,name and number.
there is a .net code similar to java code(actually exatly the same)
List<CfgDN> list = new List<CfgDN>();
List<DN> dnlist = new List<Dn>();
CfgDNQuery query = new CfgDNQuery(m_ConfService);
list = m_ConfService.RetrieveMultipleObjects<CfgDN>(query).ToList();
foreach (CfgDN item in list)
{
foo = (DN) item.DBID;
......
dnlist.Add(foo);
}
Note : DN is my class which contains some property from platform SDK.
KeyValueCollection tenantList = new KeyValueCollection();
tenantList.addString("tenant", "Resources");
RequestStartPlaceAgentStateReportingAll all = RequestStartPlaceAgentStateReportingAll.create(tenantList);
interactionServerProtocol.send(all);
I'm attempting to execute an Upsert using the Novell JLDAP library, unfortunately, I'm having trouble finding an example of this. Currently, I have to:
public EObject put(EObject eObject){
Subject s = (Subject) eObject;
//Query and grab attributes from subject
LDAPAttributes attr = resultsToAttributes(getLDAPConnection().get(s));
//No modification needed - return
if(s.getAttributes().equals(attr)){
return eObject;
} else {
//Keys:
//REPLACE,ADD,DELETE, depending on which attributes are present in the maps, I choose the operation which will be used
Map<String,LDAPAttribute> operationalMap = figureOutWhichAttributesArePresent(c.getAttributes(),attr);
//Add the Modifcations to a modification array
ArrayList<LDAPModification> modList = new ArrayList<LDAPModification>();
for(Entry entry: operationalMap.getEntrySet()){
//Specify whether it is an update, delete, or insert here. (entry.getKey());
modList.add(new LDAPModification(entry.getKey(),entry.getValue());
}
//commit
connection.modify("directorypathhere",modList.toArray(new LDAPModification[modList.size()]));
}
I'd prefer to not have to query on the customer first, which results in cycling through the subject's attributes as well. Is anyone aware if JNDI or another library is able to execute an update/insert without running multiple statements against LDAP?
Petesh was correct - the abstraction was implemented within the Novell library (as well as the UnboundId library). I was able to "upsert" values using the Modify.REPLACE param for every attribute that came in, passing in null for empty values. This effectively created, updated, and deleted the attributes without having to parse them first.
In LDAP, via LDIF files, an upset would be a single event with two steps. A remove and add of a value. This is denoted by a single dash on a line, between the remove then the add.
I am not sure how you would do it in this library. I would would try to modList.remove and then modList.add one after another and see if that works.
I need to show on my panel the working dir.
I use String value = System.getProperty("user.dir"). Afterwards i put this string on label but I receive this message on console:
The method getProperty(String, String) in the type System is not applicable for the arguments (String).
I use eclipse.
Issue
I am guessing you have not gone through GWT 101 - You cannot blindly use JAVA CODE on client side.
Explanation
You can find the list of classes and methods supported for GWT from JAVA.
https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation
For System only the following are supported.
err, out,
System(),
arraycopy(Object, int, Object, int, int),
currentTimeMillis(),
gc(),
identityHashCode(Object),
setErr(PrintStream),
setOut(PrintStream)
Solution
In your case Execute System.getProperty("user.dir") in your server side code and access it using RPC or any other server side gwt communication technique.
System.getProperty("key") is not supported,
but System.getProperty("key", "default") IS supported, though it will only return the default value as there is not system properties per se.
If you need the working directory during gwt compile, you need to use a custom linker or generator, grab the system property at build time, and emit it as a public resource file.
For linkers, you have to export an external file that gwt can download and get the compile-time data you want. For generators, you just inject the string you want into compiled source.
Here's a slideshow on linkers that is actually very interesting.
http://dl.google.com/googleio/2010/gwt-gwt-linkers.pdf
If you don't want to use a linker and an extra http request, you can use a generator as well, which is likely much easier (and faster):
interface BuildData {
String workingDirectory();
}
BuildData data = GWT.create(BuildData.class);
data.workingDirectory();
Then, you need to make a generator:
public class BuildDataGenerator extends IncrementalGenerator {
#Override
public RebindResult generateIncrementally(TreeLogger logger,
GeneratorContext context, String typeName){
//generator boilerplate
PrintWriter printWriter = context.tryCreate(logger, "com.foo", "BuildDataImpl");
if (printWriter == null){
logger.log(Type.TRACE, "Already generated");
return new RebindResult(RebindMode.USE_PARTIAL_CACHED,"com.foo.BuildDataImpl");
}
SourceFileComposerFactory composer =
new SourceFileComposerFactory("com.foo", "BuildDataImpl");
//must implement interface we are generating to avoid class cast exception
composer.addImplementedInterface("com.foo.BuildData");
SourceWriter sw = composer.createSourceWriter(printWriter);
//write the generated class; the class definition is done for you
sw.println("public String workingDirectory(){");
sw.println("return \""+System.getProperty("user.dir")+"\";");
sw.println("}");
return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING
,"com.foo.BuildDataImpl");
}
}
Finally, you need to tell gwt to use your generator on your interface:
<generate-with class="dev.com.foo.BuildDataGenerator">
<when-type-assignable class="com.foo.BuildData" />
</generate-with>