Commit 253d5d4e authored by Emilien Bondu's avatar Emilien Bondu
Browse files

First commit of the WebLab Document Viewer portlet.

git-svn-id: svn://svn.forge.objectweb.org/svnroot/weblab/trunk/WebLabServices/Portlets/document-viewer-portlet@98 a803c184-d8de-4a0e-a52b-d3eef88212b6
parent 2ea035e8
This diff is collapsed.
<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>
<properties>
<service.name>DocViewPortlet</service.name>
<eclipse.useProjectReferences>false</eclipse.useProjectReferences>
</properties>
<parent>
<groupId>org.weblab-project.portlets</groupId>
<artifactId>parent</artifactId>
<version>1.1</version>
</parent>
<groupId>org.weblab-project.portlet</groupId>
<artifactId>${service.name}</artifactId>
<packaging>war</packaging>
<version>1.1</version>
<name>${service.name}</name>
<dependencies>
<dependency>
<groupId>org.weblab-project.core</groupId>
<artifactId>rdf-helper-jena-selection</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.weblab-project.core</groupId>
<artifactId>bean-helper-spring</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.4</version>
<!-- Any implementation should be added (scope provided or test)-->
</dependency>
<dependency>
<groupId>org.weblab-project.core</groupId>
<artifactId>rdf-helper-jena</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<!-- needed because rdf-helper-jena use xerces... so xalan lib -->
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>DocViewPortlet</finalName>
</build>
</project>
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2009 EADS DEFENCE AND SECURITY SYSTEMS
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
package org.ow2.weblab.portlet.bean;
/**
* Bean representing an field in a DocumentLegend. It contains information about
* the entity that this field represent. display name, type or color.
*
* @author emilien
*
*/
public class LegendField {
private String entityType;
private String matchedValue;
private String displayName;
private String styleColor;
private String styleClassName;
private boolean show;
/**
* Public constructor
*
* @param entityType
* Entity type (For example
* "http://weblab.eads.com/property/gate/annotation")
* @param matchedValue
* value of the entity. (For example "Person")
* @param displayName
* value in the legend. (For example "Persons")
* @param styleColor
* Color of the entity in the legend.
* @param styleClassName
* style class name used for style elements.
* @param show
* show entity or not in document using this legend.
*/
public LegendField(String entityType, String matchedValue,
String displayName, String styleColor, String styleClassName,
boolean show) {
super();
this.entityType = entityType;
this.matchedValue = matchedValue;
this.displayName = displayName;
this.styleColor = styleColor;
this.styleClassName = styleClassName;
this.show = show;
}
/**
* Public constructor without parameters.
*/
public LegendField() {
//
}
/**
* Getters and setters
*/
public String getEntityType() {
return this.entityType;
}
public void setEntityType(String entityType) {
this.entityType = entityType;
}
public String getMatchedValue() {
return this.matchedValue;
}
public void setMatchedValue(String matchedValue) {
this.matchedValue = matchedValue;
}
public String getDisplayName() {
return this.displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getStyleColor() {
return this.styleColor;
}
public void setStyleColor(String styleColor) {
this.styleColor = styleColor;
}
public String getStyleClassName() {
return this.styleClassName;
}
public void setStyleClassName(String styleClassName) {
this.styleClassName = styleClassName;
}
public boolean isShow() {
return this.show;
}
public void setShow(boolean show) {
this.show = show;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2009 EADS DEFENCE AND SECURITY SYSTEMS
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
package org.ow2.weblab.portlet.bean;
/**
* Bean class representing a Named Entity A named entity has properties like
* start and end offset in a text, Value like "Person", URItype like
* "http://weblab.eads.com/property/gate/annotation" Style class name like
* "_annotation_gate_person"
*
* @author emilien
*/
public class NamedEntity {
private int startOffset;
private int endOffset;
private String entityLabel;
private String entityURI;
private String entityClassURI;
private boolean isCandidate;
/**
* @return the startOffset
*/
public int getStartOffset() {
return this.startOffset;
}
/**
* @return the isCandidate
*/
public boolean isCandidate() {
return this.isCandidate;
}
/**
* @param isCandidate
* the isCandidate to set
*/
public void setCandidate(boolean isCandidate) {
this.isCandidate = isCandidate;
}
/**
* @param startOffset
* the startOffset to set
*/
public void setStartOffset(int startOffset) {
this.startOffset = startOffset;
}
/**
* @return the endOffset
*/
public int getEndOffset() {
return this.endOffset;
}
/**
* @param startOffset
* @param endOffset
* @param entityLabel
* @param entityURI
*/
public NamedEntity(int startOffset, int endOffset, String entityLabel,
String entityURI, String entityClassURI, boolean isCandidate) {
super();
this.startOffset = startOffset;
this.endOffset = endOffset;
this.entityLabel = entityLabel;
this.entityURI = entityURI;
this.entityClassURI = entityClassURI;
this.isCandidate = isCandidate;
}
/**
* @param endOffset
* the endOffset to set
*/
public void setEndOffset(int endOffset) {
this.endOffset = endOffset;
}
/**
* @return the entityLabel
*/
public String getEntityLabel() {
return this.entityLabel;
}
/**
* @param entityLabel
* the entityLabel to set
*/
public void setEntityLabel(String entityLabel) {
this.entityLabel = entityLabel;
}
/**
* @return the entityURI
*/
public String getEntityURI() {
return this.entityURI;
}
/**
* @param entityURI
* the entityURI to set
*/
public void setEntityURI(String entityURI) {
this.entityURI = entityURI;
}
/**
* @return the entityClassURI
*/
public String getEntityClassURI() {
return this.entityClassURI;
}
/**
* @param entityClassURI
* the entityClassURI to set
*/
public void setEntityClassURI(String entityClassURI) {
this.entityClassURI = entityClassURI;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2009 EADS DEFENCE AND SECURITY SYSTEMS
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
package org.ow2.weblab.portlet.bean;
import java.util.ArrayList;
import java.util.List;
/**
* Class representing a text zone. A text zone reference a entities list.
*
* @author emilien
*/
public class TextZone {
private int textStartOffset;
private int textEndOffset;
private List<NamedEntity> entitiesList;
/**
* public constructor with parameters.
*
* @param textStartOffset
* @param textEndOffset
*/
public TextZone(int textStartOffset, int textEndOffset) {
this.textStartOffset = textStartOffset;
this.textEndOffset = textEndOffset;
this.entitiesList = new ArrayList<NamedEntity>();
}
/**
* test if a text zone equal this text zone by offset.
*
* @param tz
* @return true if tz offset equal this offset.
*/
public boolean equals(TextZone tz) {
return ((tz.textStartOffset == this.textStartOffset) && (tz.textEndOffset == this.textEndOffset));
}
/**
* check a named entitie is referenced in this text zone.
*
* @param ne
* the NamedEntity.
* @return true if the zone reference ne.
*/
public boolean reference(NamedEntity ne) {
int neStart = ne.getStartOffset();
int neEnd = ne.getEndOffset();
return ((neStart < this.textStartOffset && neEnd > this.textStartOffset) || (neStart >= this.textStartOffset && neStart < this.textEndOffset));
}
/**
* check if the text zone is an overlap zone (at least two entities
* referenced).
*
* @return true if the text zone reference at least two entities.
*/
public boolean isOverLap() {
if (this.entitiesList.size() > 1) {
return true;
}
return false;
}
/**
* check if the text zone reference at least one entity.
*
* @return true if the text zone reference at least one entity.
*/
public boolean referenceEntities() {
return this.entitiesList.size() != 0;
}
/**
* get the first entity referenced by the text zone.
*
* @return the first entity referenced by the text zone.
*/
public NamedEntity getEntityReference() {
return this.entitiesList.get(0);
}
// getters and setters
public int getTextStartOffset() {
return this.textStartOffset;
}
public void setTextStartOffset(int textStartOffset) {
this.textStartOffset = textStartOffset;
}
public int getTextEndOffset() {
return this.textEndOffset;
}
public void setTextEndOffset(int textEndOffset) {
this.textEndOffset = textEndOffset;
}
public List<NamedEntity> getEntitiesReferences() {
return this.entitiesList;
}
public void setEntitiesList(List<NamedEntity> entitiesList) {
this.entitiesList = entitiesList;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2009 EADS DEFENCE AND SECURITY SYSTEMS
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
package org.ow2.weblab.portlet.tool;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import org.apache.commons.logging.LogFactory;
import org.ow2.weblab.portlet.bean.LegendField;
import org.weblab_project.core.helper.RDFHelperFactory;
import org.weblab_project.core.helper.ResourceHelper;
import org.weblab_project.core.model.ComposedUnit;
import org.weblab_project.core.model.MediaUnit;
import org.weblab_project.core.model.Segment;
import org.weblab_project.core.model.text.Text;
import org.weblab_project.core.ontologies.RDF;
import org.weblab_project.core.ontologies.WebLab;
import org.weblab_project.core.util.ComposedUnitUtil;
/**
* Factory to make the legend of a weblab media unit. Media unit is analised to
* add all distinct annotations as fields. Each field corresponding a random
* color and a name (corresponding the annotation type).
*
* @author emilien
*/
public class LegendFactory {
private static Random random = new Random();
/**
* Constructor without parameters.
*/
private LegendFactory() {
//
}
/**
* To get the MediaUnitLegend of the media unit.
*
* @param mediaUnnit
* the media unit used to make the legend.
* @return the legend of media unit.
*/
public static MediaUnitLegend getLegend(MediaUnit mediaUnit) {
LogFactory.getLog(LegendFactory.class).info(
"Creating a new legend for media unit :" + mediaUnit.getUri());
/*
* Creating MediaUnitLegend
*/
MediaUnitLegend leg = new MediaUnitLegend();
Set<String> predicatSet = new HashSet<String>();
List<LegendField> listField = new ArrayList<LegendField>();
if (mediaUnit instanceof Text) {
/*
* media is a Text
*/
matchEntities(mediaUnit, predicatSet);
} else if (mediaUnit instanceof ComposedUnit) {
/*
* unit is a composed unit
*/
List<Text> mediaUnits = ComposedUnitUtil.getSelectedSubMediaUnits(
(ComposedUnit) mediaUnit, Text.class);
/*
* get all distinct entities
*/
for (MediaUnit unit : mediaUnits) {
matchEntities(unit, predicatSet);
}
}
/*
* build legend fields corresponding to distinct predicates
*/
for (String predicat : predicatSet) {
/*
* processing predicate without values
*/
LegendField f = new LegendField();
f.setDisplayName(predicat);
f.setEntityType(predicat);
f.setMatchedValue(null);
f.setShow(true);
String styleClassName = predicat.replace(".", "_");
styleClassName = styleClassName.replace("http://", "http_");
styleClassName = styleClassName.replace("/", "_");
styleClassName = styleClassName.replace("#", "_");
f.setStyleClassName(styleClassName);
int r = random.nextInt(255);
int g = random.nextInt(255);
int b = random.nextInt(255);
f.setStyleColor(r + "," + g + "," + b);
listField.add(f);
}
leg.setFields(listField);
return leg;
}
/**
* match all named entities of the unit and add its in the predicateSet map
* and its values in predicatValue map.
*
* @param mediaUnit
* @param predicatSet