/*******************************************************************************
* Copyright 2013
* Ubiquitous Knowledge Processing (UKP) Lab
* Technische Universität Darmstadt
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package de.tudarmstadt.ukp.csniper.webapp.evaluation.model;
import java.io.Serializable;
@SuppressWarnings("serial")
public class ItemContext
implements Serializable
{
public static int UNKNOWN = -1;
private int begin;
private int end;
private int unitBegin;
private int unitEnd;
private int matchBegin = UNKNOWN;
private int matchEnd = UNKNOWN;
private String windowText;
private int textLength = UNKNOWN;
/**
* @param aWindowText
* the window text.
* @param aBegin
* the begin of the window text relative to the full text.
* @param aEnd
* the end of the window text relative to the full text.
* @param aUnitBegin
* unit being relative to the window text.
* @param aUnitEnd
* unit end relative to the window text.
*/
public ItemContext(String aWindowText, int aBegin, int aEnd, int aUnitBegin, int aUnitEnd)
{
windowText = aWindowText;
begin = aBegin;
end = aEnd;
unitBegin = aUnitBegin;
unitEnd = aUnitEnd;
}
public int getBase()
{
return begin;
}
public int getEnd()
{
return end;
}
public boolean isMatchSet()
{
return (matchBegin >= 0) && (matchEnd >= 0);
}
/**
* Set the match offsets relative to the text.
*
* @param aBegin
* match begin.
* @param aEnd
* match end.
*/
public void setMatch(int aBegin, int aEnd)
{
matchBegin = Math.min(aBegin, aEnd);
matchEnd = Math.max(aBegin, aEnd);
}
public int getMatchBegin()
{
return matchBegin;
}
public int getMatchEnd()
{
return matchEnd;
}
public String getWindowText()
{
return windowText;
}
public String getLeft()
{
return windowText.substring(0, unitBegin);
}
public String getUnitLeft()
{
if (isMatchSet()) {
return windowText.substring(unitBegin, matchBegin);
}
else {
return "";
}
}
public String getMatch()
{
if (isMatchSet()) {
return windowText.substring(matchBegin, matchEnd);
}
else {
return getUnit();
}
}
public String getUnit()
{
return windowText.substring(unitBegin, unitEnd);
}
public String getUnitRight()
{
if (isMatchSet()) {
return windowText.substring(matchEnd, unitEnd);
}
else {
return "";
}
}
public String getRight()
{
return windowText.substring(unitEnd, windowText.length());
}
public void setTextLength(int aTextLength)
{
textLength = aTextLength;
}
public int getTextLength()
{
return textLength;
}
public int getMoreLeft()
{
return textLength > 0 ? begin : UNKNOWN;
}
public int getMoreRight()
{
return textLength > 0 ? textLength - end : UNKNOWN;
}
}