UIMA ruta - Using annotations from different views - java

I have a document, after few annotations, i am writing it into a new view using HTMLConverter
Sample Input:
<p class="MsoNormal"><span data-bkmark="para10121"></span><span style="font-family:Arial; font-size:10pt; color:#color: #000000">[1] SJ. Goetsch,BD. Murphy,R. Schmidt,et al. "Physics of rotating gamma systems for stereotactic radiosurgery. "</span> <span style="font-family:Arial; font-size:10pt; color:#color: #000000">International Journal of Radiation Oncologybiologyphysics,</span> vol.<span style="font-family:Arial; font-size:10pt; color:#color: #000000">43, no.3, pp.689-696, 1999.</span><span data-bkmark="para10121"></span></p>
I am using htmlconvertor to create a new view "plaintextview"
CONFIGURE(HtmlAnnotator, "onlyContent" = false);
Document{-> EXEC(HtmlAnnotator)};
Document { -> CONFIGURE(HtmlConverter, "inputView" = "_InitialView","outputView" = "plaintextview"),
EXEC(HtmlConverter,{TAG})};
After which i would run my own engine and perform few manual annotations
try {
for (AnnotationFS afs : CasUtil.select(cas.getView("plaintextview"), type))
{
Feature bookmarkFtr = type.getFeatureByBaseName("RefBookmark");
System.out.println("\n Ref is " + afs.getCoveredText());
System.out.println("STart is " + afs.getBegin());
System.out.println("End is " + afs.getEnd());
String test = " vol.43, no.3, pp.689-696, 1999.";
if (afs.getCoveredText().contains(test)) {
int start = afs.getCoveredText().indexOf(test) + afs.getBegin();
int end = start + test.length();
testanno annotation = new testanno(cas.getView("plaintextview").getJCas());
annotation.setBegin(start);
annotation.setEnd(end);
annotation.addToIndexes();
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
This code will annotate the particular text in the plaintextview (Why? - because the _initialview document will have html spans in between the text ex: vol.43, no.3, < some html tags > pp. 689-696, 1999.)
So how do i get my annotaions from plaintextview to initial view or use these annotaions inside my ruta script using my annotations from different views(i.e, _initialview and plaintextview) ?

In Ruta you cannot directly write rules for specific CAS views. (You could use EXEC to apply an analysis engine on the different view from within a Ruta script.)
The normal way to approach this is on framework level by either apply sofa mapping in an aggregated analysis engine or copying the view to the _initialView of a new CAS.
DISCLAIMER: I am a developer of UIMA Ruta

Related

On Camunda-Spring Integration TaskDefinition is null for active task

I have integrated Camunda Engine with Spring in our application. I want to find properties assigned to each active task for the running process instance. I am able to get the task instances with following code
List<Task> tasks = this.taskService.createTaskQuery().processInstanceId("12").list()
but if i cast task object into TaskEntity and then use getTaskDefinition() , I get null.
Other way to get task details is through ProcessDefinitionEntity.getTaskDefinitions() but it also returns null.
How should I get the task detail?
For read properties and documentation attributes use the BPMN Model API.
This example use a elementId for read both.
String processDefinitionId = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey(DEFINITON_KEY).singleResult().getId();
BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModelInstance(processDefinitionId);
ServiceTask serviceTask = (ServiceTask) bpmnModelInstance.getModelElementById(ELEMENT_ID);
// Documentation, is a collection, but the modeler supports only one attribute
Collection<Documentation> documentations = serviceTask.getDocumentations();
// Properties
Collection<Property> properties = serviceTask.getProperties();
Above answer gave me a hint but didn't solve the problem completely so here is my code which is serving the purpose.
My usertask in .bpmn file looks like:
<bpmn:userTask id="Task_063x95d" name="Tech Task">
<bpmn:documentation>SUCCESS,FAIL</bpmn:documentation>
<bpmn:extensionElements>
<camunda:inputOutput>
<camunda:inputParameter name="language">Java</camunda:inputParameter>
<camunda:outputParameter name="Platform">Linux</camunda:outputParameter>
</camunda:inputOutput>
<camunda:properties>
<camunda:property name="user" value="Test_User" />
</camunda:properties>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_1xjoyjq</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_028pkxo</bpmn:outgoing>
</bpmn:userTask>
I have analysed the .bpmn file and then just rendered its elements with help of below code
// Active tasks for currently running instanceId(input to below code)
List<Task> tasks = this.taskService.createTaskQuery().processInstanceId(instanceId).list();
String documentation= null;
for (Task task : tasks)
{
//This gives [documentation][1] field.
documentation = task.getDescription();
UserTaskImpl modelElementById = (UserTaskImpl) bpmnModelInstance.getModelElementById(tasks.get(0)
.getTaskDefinitionKey());
ExtensionElements childElementsByType2 = modelElementById.getExtensionElements();
Collection<ModelElementInstance> elements = childElementsByType2.getElements();
for (ModelElementInstance elem : elements)
{
//To access all properties.
if (elem instanceof CamundaPropertiesImpl)
{
CamundaPropertiesImpl camundaPropertiesImpl = (CamundaPropertiesImpl) elem;
Collection<CamundaProperty> camundaProperties = camundaPropertiesImpl.getCamundaProperties();
for (CamundaProperty test : camundaProperties)
{
System.out.println("camunda property name :" + test.getCamundaName() + " $ " + test.getCamundaValue());
}
}
else if (elem instanceof CamundaInputOutputImpl)
{
// To access input/output param
CamundaInputOutputImpl camundaInputOutputImpl = (CamundaInputOutputImpl) elem;
for (CamundaInputParameter test : camundaInputOutputImpl.getCamundaInputParameters())
{
log.info("camunda input params name :" + test.getCamundaName() + " $ " + test.getTextContent());
}
for (CamundaOutputParameter test : camundaInputOutputImpl.getCamundaOutputParameters())
{
log.info("camunda output params name :" + test.getCamundaName() + " $ " + test.getTextContent());
}
}
}
}

Play change Language dynamallicy

Fairly new to Play trying to change the language dynamically.
route
GET /language/:lang controllers.Index.setLanguage(lang: String)
Tried so far (but none of them work)
Lang.apply(language);
Lang.change(language); // <-- doesn't even compile
Lang.apply(language);
ctx().changeLang(language);
view
#import play.i18n.Messages
...
#Messages.get("message")
#messages.at("message")
...
Both not working..
application.config
messages
Method with some logging
public Result setLanguage(String language) {
Http.Context context = Http.Context.current();
String langFromHttpContext = context.lang().language();
String langFromCtx = ctx().lang().language();
String playLangCookieVal = request().cookies().get("PLAY_LANG").value();
boolean changed = ctx().changeLang(language);
Logger.info("Request param: " + language);
Logger.info("Http context language: " + langFromHttpContext);
Logger.info("ctx language: " + langFromHttpContext);
Logger.info("PLAY_LANG cookie value: " + langFromCtx);
Logger.info("Changed: " + changed);
return ok(index.render("Index"));
}
Result
application - Request param: en
application - Http context language: nl
application - ctx language: nl
application - PLAY_LANG cookie value: nl
application - Changed: false
You need to delete the application.langs="nl" from the configuration. It's deprecated and replaced by the play.i18n.langs.
You must leave only play.i18n.langs=["en","nl"]
You code does not work because Play reads the application.langs="nl" and ignore play.i18n.langs=["en","nl"] (because langs already read from the application.langs), so it suggest your application use only "nl" language and, of course could not set it to "en", so ctx().changeLang(language) method return false
Try this:
ctx().changeLang(language);

download cover art from musicbrainz with java

I am struggling for a couple of hours now on how to link a discid to a musicbrainz mbid.
So, using dietmar-steiner / JMBDiscId
JMBDiscId discId = new JMBDiscId();
if (discId.init(PropertyFinder.getProperty("libdiscid.path")))
{
String musicBrainzDiscID = discId.getDiscId(PropertyFinder.getProperty("cdrom.path"));
}
or musicbrainzws2-java
Disc controller = new Disc();
String drive = PropertyFinder.getProperty("cdrom.path");
try {
DiscWs2 disc =controller.lookUp(drive);
log.info("DISC: " + disc.getDiscId() + " match: " + disc.getReleases().size() + " releases");
....
I can extract a discid for freedb or musicbrainz easily (more or less), but I have not found a way on calculating the id I that I need to download cover art via the CoverArtArchiveClient from last.fm.
CoverArtArchiveClient client = new DefaultCoverArtArchiveClient();
try
{
UUID mbid = UUID.fromString("mbid to locate release");
fm.last.musicbrainz.coverart.CoverArt coverArt = client.getByMbid(mbid);
Theoretically, I assume, I could you the data collected by musicbrainzws2-java to trigger a search, and then use the mbid from the result ... but that cannot be the best option to do.
I am happy about any push into the right direction...
Cheers,
Ed.
You don't calculate the MBID. The MBID is attached on every entity you retrieve from MusicBrainz.
When getting releases by DiscID you get a list. Each entry is a release and has an MBID, accessible with getId():
for (ReleaseWs2 rel : disc.getReleases()){
log.info("MBID: " + rel.getId() + ", String: " + rel.toString());
}
You then probably want to try the CoverArtArchive (CAA) for every release and take the first cover art you get.
Unfortunately I don't know of any API documentation for musicbrainzws2 on the web. I recommend running javadoc on all source files.

Apache Commons - NNTP - "Article To List" - AWT

I am currently using Apache Commons Net to develop my own NNTP reader. Using the tutorial available I was able to use some of their code to allow me to get articles back.
The Code I am using from NNTP Section -
System.out.println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]");
Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);
System.out.println("Building message thread tree...");
Threader threader = new Threader();
Article root = (Article)threader.thread(articles);
Article.printThread(root, 0);
I need to take the articles and turn them into a List type so I can send them to AWT using something like this -
List x = (List) b.GetGroupList(dog);
f.add(CreateList(x));
My Entire code Base for this section is -
public void GetThreadList(String Search) throws SocketException, IOException {
String hostname = USE_NET_HOST;
String newsgroup = Search;
NNTPClient client = new NNTPClient();
client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
client.connect(hostname);
client.authenticate(USER_NAME, PASS_WORD);
if(!client.authenticate(USER_NAME, PASS_WORD)) {
System.out.println("Authentication failed for user " + USER_NAME + "!");
System.exit(1);
}
String fmt[] = client.listOverviewFmt();
if (fmt != null) {
System.out.println("LIST OVERVIEW.FMT:");
for(String s : fmt) {
System.out.println(s);
}
} else {
System.out.println("Failed to get OVERVIEW.FMT");
}
NewsgroupInfo group = new NewsgroupInfo();
client.selectNewsgroup(newsgroup, group);
long lowArticleNumber = group.getFirstArticleLong();
long highArticleNumber = lowArticleNumber + 5000;
System.out.println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]");
Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);
System.out.println("Building message thread tree...");
Threader threader = new Threader();
Article root = (Article)threader.thread(articles);
Article.printThread(root, 0);
try {
if (client.isConnected()) {
client.disconnect();
}
}
catch (IOException e) {
System.err.println("Error disconnecting from server.");
e.printStackTrace();
}
}
and -
public void CreateFrame() throws SocketException, IOException {
// Make a new program view
Frame f = new Frame("NNTP Reader");
// Pick my layout
f.setLayout(new GridLayout());
// Set the size
f.setSize(H_SIZE, V_SIZE);
// Make it resizable
f.setResizable(true);
//Create the menubar
f.setMenuBar(CreateMenu());
// Create the lists
UseNetController b = new UseNetController(NEWS_SERVER_CREDS);
String dog = "*";
List x = (List) b.GetGroupList(dog);
f.add(CreateList(x));
//f.add(CreateList(y));
// Add Listeners
f = CreateListeners(f);
// Show the program
f.setVisible(true);
}
I just want to take my list of returned news articles and send them to the display in AWT. Can any one explain to me how to turn those Articles into a list?
Welcome to the DIY newsreader club. I'm not sure if you are trying to get a list of newsgroups on the server, or articles.You have already have your Articles in an Iterable Collection. Iterate through it appending what you want in the list from each article. You probably aren't going to want to display the whole article body in a list view. More likely the message id, subject, author or date (or combination as a string). For example for a List of just subjects:
...
Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);
Iterator<Article> it = articles.iterator();
while(it.hasNext()) {
Article thisone = it.next();
MyList.add(thisone.getSubject());
//MyList should have been declared up there somewhere ^^^ and
//your GetThreadList method must include List in the declaration
}
return MyList;
...
My strategy has been to retrieve the articles via an iterator in to an SQLite database with the body, subject, references etc. stored in fields. Then you can create a list sorted just how you want, with a link by primary key to retrieve what you need for individual articles as you display them. Another strategy would be an array of message_ids or article numbers and fetch each one individually from the news server as required. Have fun - particularly when you are coding for Android and want to display a list of threaded messages in the correct sequence with suitable indents and markers ;). In fact, you can learn a lot by looking at the open source Groundhog newsreader project (to which I am eternally grateful).
http://bazaar.launchpad.net/~juanjux/groundhog/trunk/files/head:/GroundhogReader/src/com/almarsoft/GroundhogReader

Can not link a Series to a chart SeriesDefinitions in BIRT

I am trying hard to implement a charting extension to an app that i am developing : so my problem is that I have written some code (the boiler plate one) for doing this in BIRT.
At some place in the code, I have to link the dataset to a series and link the series to a seriesdefinition object which finally will be attached to the charts seriesDefinitions like this
RadarSeries radarSeries = RadarSeriesImpl.create();
radarSeries.setDataSet(numberDataValues);
radarSeries.setSeriesIdentifier("Number data values");
radarSeries.getLabel().setVisible(true);
where numberDataValues is an array of doubles. Then I create my seriesDefinition :
SeriesDefinition seriesDefinition = SeriesDefinitionImpl.create();
seriesDefinition.getSeriesPalette().shift(0);
But then, here comes the time when I have to LINK my radarSeries to the seriesDefinition like this :
seriesDefinition.getSeriesDefinitions().add(radarSeries);
THE PROBLEM : I don't have the getSeriesDefinitions() method when trying to call it from code (doing a Ctrl+Space in Eclipse).
Needless to say that I can't call the getSeriesDefinitions() method on myChart object :
myChart.getSeriesDefinitions().add(seriesDefinition);
FOR YOUR INFORMATION : I have included my birt jars manually in my local maven repository and the details of these dependencies are :
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>engineapi</artifactId>
<version>${birtVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>coreapi</artifactId>
<version>${birtVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>scriptapi</artifactId>
<version>${birtVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>chartengineapi</artifactId>
<version>${birtVersion}</version>
</dependency>
where ${birtVersion} = 2.6.2
here is a link to the official example of the 2.6.2 release of birt about RadarChart : Radar chart official release example
Can somebody help me ? I really can't believe I didn't found out how to do this in a 3days google search session : that not serious! ... given its popularity and its power, I think they should have invested more effort in the documentation ...
#Birt guyz (if any) > sorry to be so dramatic guys, but I really think that the doc side really sucks ... I hope to be able to help you on this (really, I do)
Here is the code :
public String drawChart() {
// Birt Vars
IDeviceRenderer iDeviceRenderer = null;
IDisplayServer iDisplayServer = null;
RunTimeContext context;
Chart chart = null;
// Birt Platform configuration
PlatformConfig platformConfig = new PlatformConfig();
platformConfig.setProperty("STANDALONE", true);
// Creating Chart Engine
ChartEngine chartEngine = ChartEngine.instance(platformConfig);
IGenerator iGenerator = chartEngine.getGenerator();
if(iGenerator == null)
System.out.println("IGenerator NULL");
else
System.out.println("IGenerator NOT NULL");
try {
// iDeviceRenderer = chartEngine.getRenderer("dv.PNG");
iDeviceRenderer = chartEngine.getRenderer("dv.GIF");
iDisplayServer = iDeviceRenderer.getDisplayServer();
} catch (Exception e) {
e.printStackTrace();
}
// Creating Chart
ChartWithoutAxes radarChart = ChartWithoutAxesImpl.create( );
radarChart.setDimension( ChartDimension.TWO_DIMENSIONAL_LITERAL );
radarChart.setType(Radar.TYPE_LITERAL); //$NON-NLS-1$
radarChart.setSubType( "Standard Radar Chart" ); //$NON-NLS-1$
// Plot
radarChart.setSeriesThickness( 10 );
// Legend
Legend lg = radarChart.getLegend( );
lg.getOutline( ).setVisible( true );
// Title
radarChart.getTitle( )
.getLabel( )
.getCaption( )
.setValue( "Radar Chart" );//$NON-NLS-1$
try {
if(radarChart != null)
System.out.println("RADAR CHART NOT NULL");
else
System.out.println("RADAR CHART NULL!!!");
// PREPARE PHASE
context = Generator.instance().prepare(radarChart, null, null, ULocale.getDefault());
if(context == null)
System.out.println("CONTEXT NULL ");
else
System.out.println("CONTEXT NOT NULL");
//BIND PHASE : fetch data from DB
NumberDataSet numberDataValues = NumberDataSetImpl.create( new double[]{
54, 21, 75, 91, 37
} );
// Radar series
RadarSeries radarSeries = RadarSeriesImpl.create();
radarSeries.setDataSet(numberDataValues);
radarSeries.setSeriesIdentifier("Number data values");
radarSeries.getLabel().setVisible(true);
SeriesDefinitionImpl seriesDefinition = (SeriesDefinitionImpl) SeriesDefinitionImpl.create();
seriesDefinition.getSeriesPalette().shift(0);
// ERROR HERE : can't call the method
seriesDefinition.getSeriesDefinitions()
// RENDERING PHASE
if(iDisplayServer == null)
System.out.println("DISPLAY SERVER NULL");
else
System.out.println("DISPLAY SERVER NOT NULL");
GeneratedChartState generatedChartState = iGenerator.build(iDisplayServer, radarChart, null, null, context);
iGenerator.render(iDeviceRenderer, generatedChartState);
} catch (Exception e) {
e.printStackTrace();
}
}
EDIT + SOLUTION
Sorry for the delay : I should have posted this answer earlier to mark this question as solved.
Just use the RCP report designer to create your report document. Copy ReportEngine/lib/*jars to your /WEB-INF/lib; also create a platform/ directory under WEB-INF/ and copy BIRT ReportEngine configuration/ and plugins/ directories under the newly created WEB-INF/platform/ folder. Now with the *.rptdesign file that you have created in your BIRT RCP designer tool, you will have to use the BIRT API which will allow you to interact with your report...
Sorry for the delay : I should have posted this answer earlier to mark this question as solved.
Just use the RCP report designer to create your report document.
Then copy ReportEngine/lib/*jars to your /WEB-INF/lib; also create a platform/ directory under WEB-INF/ and copy BIRT ReportEngine configuration/ and plugins/ directories under the newly created WEB-INF/platform/ folder.
Now with the *.rptdesign file that you have created in your BIRT RCP designer tool, you will have to use the BIRT API which will allow you to interact with your report...

Categories