|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace UPImage.FileFormat
{
////////
public class ComponentInfo
{
public int ComponentID;
public int startpoint;
public int endpoint;
public ComponentInfo()
{
ComponentID=0;
startpoint = 0;
endpoint = 0;
}
}
public class UPSEGMENT
{
private String hierachy;
private String delineation;
private String qualityLevel;
private String label;
//private int iComponentID;
//private int iOffset;
private List<ComponentInfo> componentValues;
public String Hierachy
{
get
{
return hierachy;
}
set
{
if (hierachy == value)
return;
hierachy = value;
}
}
public String Delineation
{
get
{
return delineation;
}
set
{
if (delineation == value)
return;
delineation = value;
}
}
public String QualityLevel
{
get
{
return qualityLevel;
}
set
{
if (qualityLevel == value)
return;
qualityLevel = value;
}
}
public String Label
{
get
{
return label;
}
set
{
if (label == value)
return;
label = value;
}
}
public List<ComponentInfo> ComponentValues
{
get
{
return componentValues;
}
set
{
if (componentValues == value)
return;
componentValues = value;
}
}
public UPSEGMENT()
{
componentValues = new List<ComponentInfo>();
}
};
public class UPDataAnnotations : UPDataDocumentation
{
/// <summary>
/// KEYWORD .DATE [N] [N] [N] Date stamp: month, day, year.
/// .KEYWORD .STYLE [R] PRINTED, CURSIVE or MIXED.
/// .KEYWORD .WRITER_ID [S] MANDATORY unique writer identification.
/// .KEYWORD .COUNTRY [S] Country of origin.
/// .KEYWORD .HAND [R] Writer hand: L for left, R for right.
/// .KEYWORD .AGE [N] Writer age, in years.
/// .KEYWORD .SEX [R] Writer sex: M for male, F for female.
/// .KEYWORD .SKILL [R] Skill of writer, familiarity with input device: BAD, OK or GOOD.
/// .KEYWORD .WRITER_INFO [F] Misc. information about writer.
/// .KEYWORD .SEGMENT [S] [R] [R] [L] Type of segment, its delineation, quality and label.
/// .KEYWORD .START_SET [S] Start a new set; the argument is the set name.
/// .KEYWORD .START_BOX [.]
///
///
/// </summary>
//
protected List<UPSEGMENT> segments;
//------------------------------------------------------------------------
public DateTime m_date;
public String m_style;
public String m_writer_ID;
public String m_country;
public String m_hand;
public int m_age;
public String m_sex;
public String m_skill;
public String m_writer_info;
public List<UPSEGMENT> m_Segments
{
get
{
return segments;
}
}
/// <summary>
///
/// </summary>
public UPDataAnnotations()
{
segments = new List<UPSEGMENT>();
}
/// <summary>
///
/// </summary>
/// <param name="kw"></param>
protected void SetDataAnnotations(UPKEYWORD kw)
{
switch (kw.keyName)
{
case ".DATE":
// dataAnnotations.date = kw;
break;
case ".STYLE":
// dataAnnotations.style = kw;
break;
case ".WRITER_ID":
//dataAnnotations.writer_ID = kw;
break;
case ".COUNTRY":
// dataAnnotations.country = kw;
break;
case ".HAND":
// dataAnnotations.hand = kw;
break;
case ".AGE":
// dataAnnotations.age = kw;
break;
case ".SEX":
// dataAnnotations.sex = kw;
break;
case ".SKILL":
// dataAnnotations.skill = kw;
break;
case ".WRITER_INFO":
// dataAnnotations.writer_info = kw;
break;
case ".SEGMENT":
SetUPSegment(kw);
break;
}
}
/// <summary>
///
/// </summary>
/// <param name="kw"></param>
void GetcomponentValue(String st,UPSEGMENT segment)
{
// get component values
if (st.Contains("-"))
{
String st1 = st.Substring(0, st.IndexOf("-"));
String st2 = st.Substring(st.IndexOf("-") + 1);
int offset = 0;
if (st1.Contains(":") && st2.Contains(":")) //string have 2 character ":"
{
int v1 = Convert.ToInt32(st1.Substring(0, st1.IndexOf(":")));
int v2 = Convert.ToInt32(st2.Substring(0, st2.IndexOf(":")));
if (v2 == v1)
{
offset = 0;
ComponentInfo cv=new ComponentInfo();
cv.ComponentID =v1;
cv.startpoint = Convert.ToInt32(st1.Substring(st1.IndexOf(":") + 1));
cv.endpoint = Convert.ToInt32(st2.Substring(st2.IndexOf(":") + 1));
segment.ComponentValues.Add(cv);
}
else
{
offset = v2 - v1;
ComponentInfo cv = new ComponentInfo();
//add the first component value to list
cv.ComponentID = v1;
cv.startpoint = Convert.ToInt32(st1.Substring(st1.IndexOf(":") + 1));
cv.endpoint = -1;
segment.ComponentValues.Add(cv);
//add next comp
for (int i = 1; i < offset; i++)
{
cv = new ComponentInfo();
cv.ComponentID = v1 + i;
cv.startpoint = 0;
cv.endpoint = -1;
segment.ComponentValues.Add(cv);
}
//add last component value
cv = new ComponentInfo();
cv.ComponentID =v2;
cv.startpoint = 0;
cv.endpoint = Convert.ToInt32(st2.Substring(st2.IndexOf(":") + 1));
segment.ComponentValues.Add(cv);
}
}
else if (st1.Contains(":")) //st1 have ":" but not st2
{
int v1 = Convert.ToInt32(st1.Substring(0, st1.IndexOf(":")));
int v2 = Convert.ToInt32(st2);
offset = v2 - v1;
ComponentInfo cv = new ComponentInfo();
//add the first component value to list;
cv.ComponentID = v1;
cv.startpoint = Convert.ToInt32(st1.Substring(st1.IndexOf(":") + 1)); ;
cv.endpoint = -1;
segment.ComponentValues.Add(cv);
//add next component values
if (offset > 0)
{
for (int i = 1; i <= offset; i++)
{
cv = new ComponentInfo();
cv.ComponentID = v1+i;
cv.startpoint = 0;
cv.endpoint = -1;
segment.ComponentValues.Add(cv);
}
}
}
else if (st2.Contains(":")) //st2 have ":"
{
int v1 = Convert.ToInt32(st1);
int v2 = Convert.ToInt32(st2.Substring(0, st2.IndexOf(":")));
offset = v2 - v1;
ComponentInfo cv;
//add next component values
if (offset > 0)
{
for (int i = 0; i < offset; i++)
{
cv = new ComponentInfo();
cv.ComponentID = v1 + i;
cv.startpoint = 0;
cv.endpoint = -1;
segment.ComponentValues.Add(cv);
}
//add the last component value to list;
cv = new ComponentInfo();
cv.ComponentID = v2;
cv.startpoint = 0;
cv.endpoint = Convert.ToInt32(st2.Substring(st2.IndexOf(":") + 1));
segment.ComponentValues.Add(cv);
}
else
{
cv = new ComponentInfo();
cv.ComponentID = v2;
cv.startpoint = 0;
cv.endpoint = Convert.ToInt32(st2.Substring(st2.IndexOf(":") + 1));
segment.ComponentValues.Add(cv);
}
}
else
{
int v1 = Convert.ToInt32(st1);
int v2 = Convert.ToInt32(st2);
offset = v2 - v1;
ComponentInfo cv;
//add next component values
for (int i = 0; i <= offset; i++)
{
cv = new ComponentInfo();
cv.ComponentID = v1 + i;
cv.startpoint = 0;
cv.endpoint = -1;
segment.ComponentValues.Add(cv);
}
}
}
else if (st.Contains(":")) //string not have "-" but ":"
{
String st1 = st.Substring(0, st.IndexOf(":"));
String st2 = st.Substring(st.IndexOf(":") + 1);
ComponentInfo cv = new ComponentInfo();
cv.ComponentID = Convert.ToInt32(st1);
cv.startpoint = Convert.ToInt32(st2); ;
cv.endpoint = -1;
segment.ComponentValues.Add(cv);
}
else //string does not have "-" nether ":"
{
ComponentInfo cv = new ComponentInfo();
cv.ComponentID = Convert.ToInt32(st);
cv.startpoint = 0;
cv.endpoint = -1;
segment.ComponentValues.Add(cv);
}
//
}
void SetUPSegment(UPKEYWORD kw)
{
try
{
if (kw.keyName == UPImage.Common.UpCommonLib.keySegment)
{
String content = "";
foreach (var s in kw.content_list)
{
String tempSt = "";
if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, UPImage.Common.UpCommonLib.keySegment))
{
tempSt = s.Substring(s.IndexOf(" ")).Trim();
}
else
{
tempSt = s.Trim();
}
//check parameters
if (!String.IsNullOrWhiteSpace(tempSt))
{
content = String.Format("{0} {1}", content, tempSt);
}
}
// add data to segment structure
if (content != "")
{
List<String> st_list = new List<string>();
UPSEGMENT segment = new UPSEGMENT();
segment.Label = content.Substring(content.IndexOf("\"")).Trim();
content = content.Substring(0, content.IndexOf("\"") - 1).Trim();
UPImage.Common.UpCommonLib.GetWordsFromString(null, content, out st_list);
segment.Hierachy = st_list[0].Trim();
segment.Delineation = st_list[1].Trim();
segment.QualityLevel = st_list[2].Trim();
try
{
string st = segment.Delineation;
st = UPImage.Common.UpCommonLib.ReplaceSubString(st, ",", " ");
List<String> slist = new List<string>();
UPImage.Common.UpCommonLib.GetWordsFromString(null, st, out slist);
if (slist.Count > 0)
{
foreach (var item in slist)
{
GetcomponentValue(item, segment);
}
}
else
{
GetcomponentValue(st, segment);
}
//add segment to list
segments.Add(segment);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.