id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
85f0c9f3-b12a-4923-99a0-902fa7db75dd | public void execute() {
String result = null;
Environment env = Environment.valueOf("SYSTEM");
InputReader inputReader = env.getInputReader();
OutputWriter outputWriter = env.getOutputWriter();
InputValidator validator = new InputValidator();
InputParser parser = new InputParser();
String input = inputReader.ReadInput();
try {
int value = validator.validate(input);
result = parser.parse(value);
} catch (ValidationException e) {
result = e.getMessage();
}
outputWriter.writeOutput(result);
} |
5406bc6d-2127-48dc-b0b0-3367376e9cb6 | public ValidationException() {
super("Invalid Number");
} |
d6b4917a-11bd-428d-9002-663631490131 | public InputParser() {
} |
f56de4f4-731e-406c-b600-150041a2cccd | public String parse(int input) {
for (int i = 2 ; i >= 0 ; i--) {
int j = (int)Math.pow(1000, i);
int k = input / j;
if (k > 0) {
buildSegment(k, i);
input = input - (k * j);
}
}
return result.toString().trim();
} |
4aa235e6-eea1-4668-aafa-736fdc63e1c0 | private void buildSegment(int segment, int order) {
// test if any hundreds
int i = segment / 100;
if (i > 0) {
result.append(SPACE).append(PuzzleModel.DIGITS[i-1]).append(SPACE).append(HUNDRED);
}
// anything in the range 00 - 99
int j = segment % 100;
if (j > 0) {
// have we already output something for hundreds or we have something in the last segment
if (i > 0 || (order == 0 && j > 0 && result.length() > 0)) {
result.append(SPACE).append(AND);
}
if (j < 20) {
result.append(SPACE).append(PuzzleModel.DIGITS[j-1]);
} else {
result.append(SPACE).append(PuzzleModel.TENS[j/10 -1]);
// check for any units
int k = j % 10;
if (k > 0) {
result.append(SPACE).append(PuzzleModel.DIGITS[k-1]);
}
}
if (segment > 0) {
result.append(SPACE).append(PuzzleModel.HUNDREDS[order]);
}
}
} |
506cc30e-252f-44f6-9eed-b95b6bc36b98 | public static void main(String[] args) {
PuzzleController controller = new PuzzleController();
controller.execute();
} |
dc0ae775-496d-4661-8346-e525380f627a | @Override
public InputReader getInputReader() {
return new SystemInputReader();
} |
98404162-2075-45c2-9cd9-6a3e4c40c1f7 | @Override
public OutputWriter getOutputWriter() {
return new SystemOutputWriter();
}}; |
536ef17f-b7bb-438d-822b-02309d892131 | public abstract InputReader getInputReader(); |
fc62f6f5-67dd-4175-96e9-bbbb64106efa | public abstract OutputWriter getOutputWriter(); |
e66d034e-8c75-44d8-867d-d18b5cce041c | void writeOutput(String result); |
edb33157-510b-41ee-90bf-1ff59d8f890f | public InputValidator() {
} |
b5db49db-9530-401a-a414-530523c30bd6 | public int validate(String input) throws ValidationException {
boolean commasEntered = false;
// check to see if comma formatted
if (input.length() > 5 && input.charAt(input.length() - 4) == COMMA) {
commasEntered = true;
}
// parse the string in reverse to ensure commas are correct if entered
for (int i = input.length() - 1; i > 0; i--) {
if (commasEntered && (input.length() - i) % 4 == 0) {
if (!(input.charAt(i) == COMMA)) {
throw new ValidationException();
}
} else {
if (!Character.isDigit(input.charAt(i))) {
throw new ValidationException();
}
}
}
// make sure the most significant digit is 1 - 9
if (input.charAt(0) == '0' || input.charAt(0) == ',') {
throw new ValidationException();
}
int parsedValue = Integer.parseInt(input.replaceAll(",", ""));
if (parsedValue > MAX_VALUE) {
throw new ValidationException();
}
return parsedValue;
} |
11d3d090-6abb-4215-8eda-955afeb8c0a2 | @Override
public String ReadInput() {
System.out.print(PROMPT);
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
scanner.close();
return input;
} |
a53df676-2846-4af4-812b-223e74ce18b6 | @Override
public void writeOutput(String result) {
System.out.println(result);
System.out.println("");
} |
304e15aa-766b-450e-8f3a-541c2ceb9187 | public static void main(String[] args) {
if (args.length>0) {
String file = args[0];
int scale = new Integer(args[1]);
int factorF0 = new Integer(args[2]);
System.out.println("file="+file);
Analyze analyze = new Analyze();
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(file);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
String[] split = strLine.split("\t");
String loc = new String(split[1].trim());
if (split.length>4 && !loc.matches("File")) {
Locutor locutor = analyze.getLocutor(loc);
String ti = split[2].trim();
Tier tier = locutor.getTier(ti);
String sLabel = split[3].trim();
float sStart = Sample.computeFloatValue(split[4]);
float sDur = Sample.computeFloatValue(split[5]);
float sDurP1 = Sample.computeFloatValue(split[6]);
float sDurP2 = Sample.computeFloatValue(split[7]);
float sF0Beg = Sample.computeFloatValue(split[12]);
float sF0Mid = Sample.computeFloatValue(split[13]);
float sF0End = Sample.computeFloatValue(split[14]);
Sample sample = new Sample(sLabel);
sample.setDurations(sDur, sDurP1, sDurP2);
sample.setStart(sStart);
sample.setF0Beg(sF0Beg);
sample.setF0Mid(sF0Mid);
sample.setF0End(sF0End);
tier.addSample(sample);
}
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
analyze.compute();
// System.out.println(analyze.toXML());
Writer output=null;
try {
//use buffering
output = new BufferedWriter(new FileWriter("/tmp/out.xml"));
//FileWriter always assumes default encoding is OK!
// output.write(analyze.meansToXML());
output.write(analyze.printMeanTotal());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (output!=null)
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
analyze.generatePNG(scale, factorF0);
System.out.println("<<< END");
}
} |
951c5643-4e97-49a8-b699-479756e04d18 | public PraatChart() {
this(2, 2);
} |
abfe1602-8f67-4a35-9bab-3d91dbbff488 | public PraatChart(int scale, int factorF0) {
this.scale = scale;
this.factorF0 = factorF0; //4
w = 800*scale;
h = 550*scale;
sc = 600*scale;
img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
} |
73e2f6f7-1940-430c-86ff-b798179d082a | public void generateChart() {
generateChart(null);
} |
92b83a80-b634-46a1-9791-bcf89320953a | public void generateChart(SampleMean mean) {
String title = mean.getLabel().split(":")[0];
String labelBottom = "Syllables";
String labelRight = "Duration";
String labelLeft = "F0";
Graphics2D ig = img.createGraphics();
// Set drawing attributes for the foreground.
// Most importantly, turn on anti-aliasing.
ig.setStroke(new BasicStroke(2.0f)); // 2-pixel lines
ig.setFont(new Font("Serif", Font.BOLD, 12*scale)); // 12-point font
ig.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias
RenderingHints.VALUE_ANTIALIAS_ON);
int m100 = 100*scale;
int m50 = 50*scale;
int m400 = 400*scale;
ig.setColor(Color.white);
ig.fillRect(0, 0, w, h);
ig.setColor(Color.black);
ig.fillRect(m100-2*scale, m50-2*scale, sc+2*scale, m400+4*scale);
ig.setColor(Color.white);
ig.fillRect(m100, m50, sc-2*scale, m400);
float totalDuration = mean.getTotalChildsMeanDuration()*100;
int size = mean.getChilds().size();
float factor = (sc+(size/2)*scale)/totalDuration;
if (size==1) factor*=0.5;
if (size==2) factor*=0.75;
int x = m100;
int minLeft = 0;
int maxLeft = 0;
int maxRight = 0;
int index = 0;
for (SampleMean child: mean.getChilds().values()) {
int val = (int)(child.getMeanDuration()*100);
// for (int val: xBars) {
if (val>maxRight) maxRight=val;
int dw = (int)(val*factor);
int dh = (int)(val*factor);
if (size==1) dw/=0.5;
if (size==2) dw/=0.75;
// DRAW CHART
ig.setColor(Color.black);
int dec = 0;
if (scale>3) dec=scale;
// if (index<size-1) dec = dec-2*scale;
ig.fillRect(x+scale, h-dh-m100-scale, dw-3*scale-dec, dh);
ig.setPaint(new GradientPaint(160F*scale, 120F*scale, Color.lightGray,260F*scale, 190F*scale, Color.gray, true));
ig.fillRect(x+2*scale, h-dh-m100, dw-5*scale-dec, dh-2*scale);
// SUB CHARTS
int ssize = child.getChilds().size();
int sindex=0;
int stotal = (int)(child.getTotalChildsMeanDuration()*100);
int ssum = 0;
int sh = dh-2*scale;
for (SampleMean schild: child.getChilds().values()) {
int dx = x+dw/2;
String slabel = schild.getLabel().split(":")[1];
int alpha = 255*sindex/ssize;
ig.setColor(new Color(255, 255, 255, alpha));
int smeand = (int)(schild.getMeanDuration()*100);
int yp = h-dh-m100+ssum*sh/stotal;
int hp = sh*smeand/stotal;
ig.fillRect(x+2*scale, yp, dw-5*scale-dec, hp);
ssum += smeand;
ig.setFont(new Font("Arial", Font.BOLD, 12*scale));
int lw = ig.getFontMetrics().stringWidth(slabel);
int lh = ig.getFontMetrics().getHeight()/2;
ig.setColor(Color.black);
ig.drawString(slabel, dx-(lw/2), yp+(hp/2)+lh);
sindex++;
}
// /DRAW SUB CHARTS
// DRAW FREQUENCIES
for (Locutor locutor: child.getEntities().getLocutors().values()) {
float[] f0t = new float[3];
for (int if0=0 ; if0<3 ; if0++) {
f0t[if0] = child.getMeanF0(if0, locutor);
int f0scale = (int)f0t[if0]*scale*4;
if (f0scale<minLeft) minLeft = f0scale;
if (f0scale>maxLeft) maxLeft = f0scale;
}
boolean ignored = false;
for (float f0: f0t) {
if (f0==Sample.UNDEFINED) ignored=true;
}
if (ignored) continue;
int dwf = dw-3*scale-dec;
int[] xPoints = new int[3];
int[] yPoints = new int[3];
xPoints[0] = x + 5*scale;
xPoints[1] = x + dwf/2;
xPoints[2] = x + dwf - 5*scale;
yPoints[0] = 250*scale - (int)f0t[0]*scale*factorF0;
yPoints[1] = 250*scale - (int)f0t[1]*scale*factorF0;
yPoints[2] = 250*scale - (int)f0t[2]*scale*factorF0;
ig.setColor(locutor.getColor());
float dashes[] = { 10 };
ig.setPaint( locutor.getColor() );
ig.setStroke( new BasicStroke( 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10, dashes, 0 ) );
ig.drawPolyline(xPoints, yPoints, 3);
int iloc = new Integer(locutor.getName()).intValue();
int wp = 2;
drawPicto(ig, xPoints[0], yPoints[0], iloc, wp);
drawPicto(ig, xPoints[1], yPoints[1], iloc, wp);
drawPicto(ig, xPoints[2], yPoints[2], iloc, wp);
}
// DRAW FREQUENCIES
// /DRAW CHARTS
// BOTTOM INDICATORS
ig.setColor(Color.black);
int dx = x+dw/2;
ig.drawLine(dx, h-m100+scale, dx, h-m100+4*scale);
int lw = ig.getFontMetrics().stringWidth(child.getLabel());
ig.drawString(child.getLabel(), dx-(lw/2), h-80*scale);
// /BOTTOM INDICATORS
index++;
x+=dw;
}
// Clear top graph
ig.setColor(Color.white);
ig.fillRect(0, 0, w, m50-2*scale);
ig.setColor(Color.black);
// LOCUTORS LEGENDS
int iloc= 0;
Collection<Locutor> coll = mean.getChildLocutors().values();
List<Locutor> locutors = new ArrayList<Locutor>(coll);
Collections.sort(locutors, LOCUTOR_ORDER);
for (Locutor locutor: locutors) {
ig.setColor(locutor.getColor());
String name = "L "+locutor.getName();
int lw = ig.getFontMetrics().stringWidth(name);
ig.setStroke( new BasicStroke( scale, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND) );
ig.drawString(name, 130*scale+50*scale*iloc, h- 15*scale);
ig.drawRect(126*scale+50*scale*iloc, h- 30*scale, lw+8*scale, 20*scale);
int il = new Integer(locutor.getName()).intValue();
drawPicto(ig, 118*scale+50*scale*iloc, h-20*scale, il, 4);
iloc++;
}
// /LOCUTORS LEGENDS
ig.setStroke(new BasicStroke(scale)); // 2-pixel lines
// LEFT INDICATORS
ig.setColor(Color.black);
// System.out.println("MIN:"+minLeft+" MAX:"+maxLeft);
for (int ym = 0 ; ym<5 ; ) {
ig.drawLine(m100-2*scale, 250*scale-ym*200, m100-4*scale, 250*scale-ym*200);
String lab = ""+ym*20;
int wstr = ig.getFontMetrics().stringWidth(lab);
ig.drawString(lab, m100-8*scale-wstr, 250*scale-ym*200+4*scale);
if (ym*200>maxLeft) ym=5;
ym++;
}
for (int ym = 1 ; ym<5 ; ) {
ig.drawLine(m100-2*scale, 250*scale+ym*200, m100-4*scale, 250*scale+ym*200);
String lab = "-"+ym*20;
int wstr = ig.getFontMetrics().stringWidth(lab);
ig.drawString(lab, m100-8*scale-wstr, 250*scale+ym*200+4*scale);
if (-ym*200<minLeft) ym=5;
ym++;
}
// /LEFT INDICATORS
// RIGHT INDICATORS
ig.setColor(Color.black);
int dm = h- (int)(maxRight*factor) - m100 - scale;
int dm0 = h - m100;
int ecart = (dm-dm0)/4;
for (int i=0 ; i<5 ; i++) {
ig.drawLine(sc+m100, dm0+i*ecart, sc+m100+2*scale, dm0+i*ecart);
int val = maxRight/4*i;
ig.drawString(""+val, sc+m100+7*scale, dm0+i*ecart+4*scale);
}
// /RIGHT INDICATORS
//LABELS
ig.setFont(new Font("Serif", Font.BOLD, 16*scale));
int tw = ig.getFontMetrics().stringWidth(title);
ig.drawString(title, w/2-tw/2, 30*scale);
ig.setFont(new Font("Serif", Font.BOLD, 14*scale));
int lw = ig.getFontMetrics().stringWidth(labelBottom);
ig.drawString(labelBottom, w/2-lw/2, h-55*scale);
Font font = ig.getFont();
AffineTransform fontAT = new AffineTransform();
fontAT.rotate(Math.PI/2);
Font rFont = font.deriveFont(fontAT);
ig.setFont(rFont);
ig.drawString(labelRight, w-m50, (h/2)-50*scale);
fontAT.rotate(Math.PI);
rFont = font.deriveFont(fontAT);
ig.setFont(rFont);
ig.drawString(labelLeft, 60*scale, (h/2)-20*scale);
ig.setFont(font);
// /LABELS
} |
be718371-730c-43f8-8077-5b72e4d4e6f5 | public void exportPNGImage(String filename) {
File thumbnailFile = new File(filename);
try {
ImageIO.write(img, "png", thumbnailFile);
} catch (IOException e) {
e.printStackTrace();
}
} |
6a5c769d-b70e-4648-94b5-6740e3e42262 | private void drawPicto(Graphics2D ig, int x, int y, int type, int width) {
ig.setStroke( new BasicStroke( 2*width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND) );
int step = width*scale;
int size = 2*step;
// Color ctemp = ig.getColor();
// ig.setColor(Color.white);
// ig.fillRect(x-step, y-step, size, size);
// ig.setColor(ctemp);
switch (type) {
case 1:
ig.fillArc(x-step, y-step, size, size, 0, 360);
break;
case 2:
ig.fillRect(x-step, y-step, size, size);
break;
case 3:
ig.fillPolygon(new int[]{x-step, x, x+step, x}, new int[]{y, y-step, y, y+step}, 4);
break;
case 4:
ig.fillPolygon(new int[]{x-step, x, x+step}, new int[]{y+step, y-step, y+step}, 3);
break;
case 5:
ig.drawLine(x, y-step, x, y+step);
ig.drawLine(x-step, y, x+step, y);
break;
case 6:
ig.drawLine(x-step, y-step, x+step, y+step);
ig.drawLine(x-step, y+step, x+step, y-step);
break;
case 7:
ig.drawArc(x-step, y-step, size, size, 0, 360);
break;
case 8:
ig.drawRect(x-step, y-step, size, size);
break;
case 9:
ig.drawPolygon(new int[]{x-step, x, x+step, x}, new int[]{y, y-step, y, y+step}, 4);
break;
case 10:
ig.drawPolygon(new int[]{x-step, x, x+step}, new int[]{y+step, y-step, y+step}, 3);
break;
default:
ig.fillArc(x-step/2, y-step/2, size/2, size/2, 0, 360);
}
} |
ef4cd071-000d-4c58-9de2-c66ceb8b52e9 | public int compare(Locutor l1, Locutor l2) {
try {
Integer i1 = new Integer(l1.getName());
Integer i2 = new Integer(l2.getName());
return i1.compareTo(i2);
} catch (NumberFormatException e) {
e.printStackTrace();
}
return l1.getName().compareTo(l2.getName());
} |
6ba046fd-e77d-44c2-ab25-f2ee29b0a318 | public Locutor(String name) {
tiers = new LinkedHashMap<String, Tier>(3);
// sampleTree = new LinkedHashMap<String, Sample>(20);
this.name = name;
Random rand = new Random();
color = new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256), 255);
// int c = rand.nextInt(256);
// color = new Color(c, c, c, 255);
} |
dd098369-71df-44e0-84a2-ed3cb46954e8 | public Tier getTier(String name) {
Tier tier = tiers.get(name);
if (tier == null) {
tier = new Tier(name);
tiers.put(name, tier);
}
return tier;
} |
9025f46b-5135-4d3f-bf5c-8b1308b09003 | public Collection<Tier> getTiers() {
return tiers.values();
} |
25ad8a0e-295f-4e3d-9880-8000403c5f27 | public Color getColor() {
return color;
} |
66002900-2f81-40c9-b074-848c21a3fd54 | public String getName() {
return name;
} |
e582477f-5978-4a58-b241-415c5be5b44b | public void setName(String name) {
this.name = name;
} |
1c301450-cf4f-4d4f-9807-aeaa6ecc6ebf | public String toXML() {
StringBuffer sb = new StringBuffer();
sb.append("<locutor name=\""+name+"\">");
for (Tier tier : tiers.values()) {
sb.append("\n\t");
sb.append(tier.toXML());
}
sb.append("</locutor>\n");
return sb.toString();
} |
08de475c-7a88-4a07-aeab-adb3f16d2514 | public Analyze() {
locutors = new LinkedHashMap<String, Locutor>(10);
} |
7ee09f4b-abb0-4dd4-9996-6d8f98c2f45f | public Locutor getLocutor(String name) {
Locutor locutor = locutors.get(name);
if (locutor == null) {
locutor = new Locutor(name);
// locutor.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
locutors.put(name, locutor);
}
return locutor;
} |
75f04630-e8fe-47cb-bdab-508cf26c8b5d | public Collection<Locutor> getLocutors() {
return locutors.values();
} |
3785fb3a-fdf1-4911-b074-281b9b8924b5 | public String toXML() {
StringBuffer sb = new StringBuffer();
sb.append("<analyze>");
for (Locutor locutor : locutors.values()) {
sb.append("\n\t");
sb.append(locutor.toXML());
}
sb.append("</analyze>\n");
return sb.toString();
} |
8a7ebbf5-063f-467b-8cda-00d2b49e0f39 | public String meansToXML() {
StringBuffer sb = new StringBuffer();
sb.append("<means>");
// for (SampleMean mean : means.values()) {
// if (mean.getTierName().equals(Tier.TIER_ORTHO)) {
// sb.append("\n\t");
// sb.append(mean.toXML());
// }
// }
sb.append("</means>\n");
return sb.toString();
} |
2c14b9c1-1460-437b-bcca-04254c6da207 | private void normalize() {
System.out.println(">>> NORMALIZATION");
//normalize sample.duration for all tiers/locutors
for (Locutor loc: getLocutors()) {
for (Tier tier: loc.getTiers()) {
// System.out.println("LOC :: "+loc.getName()+" TIER::"+tier.getName());
tier.normalize();
}
}
} |
90c0c0ab-b968-4f4a-a887-227aa2fe1006 | public void compute() {
System.out.println(">>> COMPUTE");
normalize();
SampleMean temp = new SampleMean("All the T3 samples");
for (Locutor loc: getLocutors()) {
compute(temp, loc, loc.getTier(Tier.TIER_ORTHO));
}
// KEEP ONLY ORTHO WITH SYLLABLES
meanTotal = new SampleMean("All the T3 samples");
for (SampleMean child: temp.getChilds().values()) {
if (child.getChilds().size()>0) {
meanTotal.getChilds().put(child.getLabel(), child);
}
}
} |
23c0e4bd-202c-4cc3-948f-a0a561f4d6d8 | private void compute(SampleMean mean, Locutor loc, Tier tier) {
compute(mean, loc, tier, null);
} |
464bbffb-d761-4332-a3aa-bb0c9f58ee33 | private void compute(SampleMean mean, Locutor loc, Tier tier, Sample sampleParent) {
cpt++;
// System.out.println(">>> COMPUTE");
for (Sample sample: tier.getSamples()) {
boolean isChild = true;
if (sampleParent!=null) {
// String plabel = "PARENT : "+sampleParent.getLabel();
float pstart = sampleParent.getStart()-1f;
float pend = sampleParent.getEnd()+1f;
// if (tier.equals(Tier.TIER_SYLL)) pend += 1f;
// String label = "CHILD : "+ sample.getLabel();
float start = sample.getStart();
float end = sample.getEnd();
isChild = (start>=pstart && end<=pend) ;
// if (plabel.startsWith("PARENT : A či je ")) {
// int i=1;
// }
}
if (isChild) {
/* Find Unique Label :
* If phonem : Parent Syllale label + Phonem label
* If syllable : Syllable label
* If ortho : Ortho label + Syllable label
*/
String label = sample.getLabel();
if (tier.getName().equals(Tier.TIER_PHONO)) {
// Sample parent = Util.getContainer(sample, loc.getTier(Tier.TIER_SYLL).getSamples());
// if (parent!=null) {
label = sampleParent.getLabel()+":"+label;
// }
} else if (tier.getName().equals(Tier.TIER_ORTHO)) {
Sample firstChild = Util.getFirstChild(sample, loc.getTier(Tier.TIER_SYLL).getSamples());
if (firstChild!=null) {
label = label + ":" + firstChild.getLabel();
}
}
// End Unique Label
SampleMeans childs = mean.getChilds();
SampleMean smean = childs.get(label);
if (smean==null) {
smean = new SampleMean(label);
childs.put(label, smean);
}
// System.out.println(cpt+":: L"+loc.getName()+" : T"+tier.getName()+" : "+mean.getLabel()+" <== "+smean.getLabel());
Entity entity = new Entity(loc, tier, sample);
smean.addEntity(entity);
if (tier.getName().equals(Tier.TIER_ORTHO)) {
compute(smean, loc, loc.getTier(Tier.TIER_SYLL), sample);
} else if (tier.getName().equals(Tier.TIER_SYLL)) {
compute(smean, loc, loc.getTier(Tier.TIER_PHONO), sample);
}
}
}
} |
86c8cb96-7d51-4206-8cef-680ce3696dda | public String printMeanTotal() {
return meanTotal.toXML();
} |
623b4ae1-cfa9-4c81-862d-f72fb56e378d | public void generatePNG(int scale, int factorF0) {
System.out.println(">>> GENERATE PNG CHARTS");
boolean debug = false;
PraatChart chart = new PraatChart(scale, factorF0);
if (debug) {
SampleMean mean = (SampleMean)meanTotal.getChilds().values().toArray()[0];
chart.generateChart(mean);
chart.exportPNGImage("out/debug.png");
} else {
int i=0;
for (SampleMean mean : meanTotal.getChilds().values()) {
i++;
String file = Util.cleanString(mean.getLabel());
System.out.println(">>>>>> GENERATE CHART "+i+" : "+mean.getLabel()+" : "+file);
chart.generateChart(mean);
chart.exportPNGImage("out/"+file+"-"+i+".png");
}
}
} |
35f1b280-bf07-40d1-80b9-17ba55061887 | public Tier (String name) {
samples = new ArrayList<Sample>(30);
this.name = name;
} |
500bd65c-b30c-49f2-8623-17f784c6ec40 | public void addSample(Sample sample) {
if (!sample.getLabel().matches(IGNORED_SAMPLE_REGEXP)) {
this.samples.add(sample);
}
} |
ae7786cb-4c41-4453-8b55-56fa8c8e655f | public Collection<Sample> getSamples() {
return samples;
} |
f2d00161-b1c7-451c-97fe-97e613b2fdca | public String getName() {
return name;
} |
27f7fd7b-79f7-4fc0-b0af-167ca3502952 | public void setName(String name) {
this.name = name;
} |
0f0dead1-39dd-4ff0-ba1a-5c10fc793e00 | public void normalize() {
if (!name.equals(Tier.TIER_ORTHO))
normalizeDuration();
if (name.equals(Tier.TIER_SYLL))
normalizeF0();
} |
d46ab51d-b7ca-4054-bf35-d72d8e9cb4f8 | public void normalizeDuration() {
ArrayList<Float> values = new ArrayList<Float>();
for (Sample sample: samples) {
if (sample.getDuration()!=Sample.UNDEFINED) {
values.add(sample.getDuration());
}
}
float M = Util.getMean(values);
for (Sample sample: samples) {
if (sample.getDuration()!=Sample.UNDEFINED) {
sample.setNormDuration(Util.getStandardizeValue(sample.getDuration(), M));
}
}
} |
b8c88608-54bb-4b27-aa3b-f9c3d081a853 | public void normalizeF0() {
ArrayList<Float> values = new ArrayList<Float>();
for (int i=0 ; i<3 ; i++) {
for (Sample sample: samples) {
if (sample.getF0()[i]!=Sample.UNDEFINED) {
values.add(sample.getF0()[i]);
} else {
sample.setF0Beg(Sample.UNDEFINED);
sample.setF0Mid(Sample.UNDEFINED);
sample.setF0End(Sample.UNDEFINED);
}
}
}
float M = Util.getMean(values);
float dev = Util.getStandardDeviation(values);
for (int i=0 ; i<3 ; i++) {
// ArrayList<Float> values = new ArrayList<Float>();
// for (Sample sample: samples) {
// if (sample.getF0()[i]!=Sample.UNDEFINED) {
// values.add(sample.getF0()[i]);
// }
// }
// float M = Util.getMean(values);
// float dev = Util.getStandardDeviation(values);
for (Sample sample: samples) {
if (sample.getF0()[i]!=Sample.UNDEFINED) {
sample.setNormF0(Util.getStandardizeValue(sample.getF0()[i], M, dev), i);
}
}
}
} |
eff0289c-5e00-476a-871b-66d5f1116ea1 | public String toXML() {
StringBuffer sb = new StringBuffer();
sb.append("<tier name=\""+name+"\">");
for (Sample sample : samples) {
sb.append("\n\t");
sb.append(sample.toXML());
}
sb.append("</tier>\n");
return sb.toString();
} |
899e445e-ef26-4bf5-b305-3db4486ec5fa | public Sample (String label) {
this.label = label;
// this.subSamples = new TreeMap<Float, Sample>();
this.isNormalized = false;
F0 = new float[]{UNDEFINED, UNDEFINED, UNDEFINED};
normF0 = new float[]{UNDEFINED, UNDEFINED, UNDEFINED};
} |
5e722f44-b115-472d-ae40-94cce68dba5a | public void setDurations(float duration, float durationp1, float durationp2) {
this.duration = duration;
this.durationp1 = durationp1;
this.durationp2 = durationp2;
} |
1c1fe1d7-d6d0-4b74-ae1c-2fe906630319 | public String getLabel() {
return label;
} |
ff13ce5c-1909-4c0f-9659-5053740216c4 | public void setLabel(String label) {
this.label = label;
} |
2f6e1050-ffa2-43c5-8dd0-5e31479f3665 | public float getDuration() {
return duration;
} |
ca809254-c65b-47e2-9118-509df5a14f0d | public void setDuration(float duration) {
this.duration = duration;
} |
5abae962-e011-43fb-9806-0e32e08a7fb0 | public float getDurationp1() {
return durationp1;
} |
2f32b7cd-081f-4031-bc12-017a7bfeca5f | public void setDurationp1(float durationp1) {
this.durationp1 = durationp1;
} |
2735e461-2195-493f-8ade-0bf5dcd4eff0 | public float getDurationp2() {
return durationp2;
} |
a397d223-04ba-4c11-abf9-b1dc2fd73c2f | public void setDurationp2(float durationp2) {
this.durationp2 = durationp2;
} |
52f33e58-3e34-42da-ac8e-35a73745a941 | public float getNormDuration() {
return normDuration;
} |
94abf8c9-0b3a-474d-9f77-59704278c714 | public void setNormDuration(float normDuration) {
this.normDuration = normDuration;
this.isNormalized = true;
} |
e2b7138c-5929-4520-b6bd-4f7c9913b7b1 | public boolean isNormalized() {
return isNormalized;
} |
8fc8169e-0479-4315-8eb8-faa67d819fc7 | public float getStart() {
return start*1000;
} |
a5d89df2-11ec-41da-a23e-5f02900583d3 | public float getEnd() {
return start*1000+duration;
} |
81d842fb-e2ea-4dc0-ae58-71c0fc2b2ba3 | public void setStart(float start) {
this.start = start;
} |
e6a36db3-e8be-4300-b094-4f5319776118 | public float[] getF0() {
return F0;
} |
36a9f40e-cb32-4609-be51-22c379adc798 | public void setF0Beg(float f0) {
F0[0] = f0;
} |
69a61c21-dd2c-47e3-b3e4-4feb96cf98ed | public void setF0Mid(float f0) {
F0[1] = f0;
} |
34ca53d7-c7b5-4bc2-8ec6-722ef95e0b7d | public void setF0End(float f0) {
F0[2] = f0;
} |
d92c2259-4157-4c0a-9b25-4899127b8dcd | public float[] getNormF0() {
return normF0;
} |
c9874d0f-50c1-4dd0-bd27-678dfcae3c96 | public void setNormF0(float normF0, int index) {
this.normF0[index] = normF0;
} |
9a3a8d50-884a-4357-9b4c-c0527e070cbe | public static final float computeFloatValue(String s) {
float f;
try {
f = new Float(s.trim()).floatValue();
} catch (NumberFormatException e) {
f = Sample.UNDEFINED;
}
return f;
} |
99138e92-df8a-4ed8-8b58-5f486b4008b5 | public String toXML() {
StringBuffer sb = new StringBuffer();
sb.append("<sample label=\""+label+"\">");
sb.append("\n\t<start>"+start+"</start>");
sb.append("\n\t<duration>"+duration+"</duration>");
sb.append("\n\t<norm-duration>"+normDuration+"</norm-duration>");
// sb.append("\n\t<durationp1>"+durationp1+"</durationp1>");
// sb.append("\n\t<durationp2>"+durationp2+"</durationp2>");
sb.append("\n\t<f0 beg=\""+F0[0]+"\" mid=\""+F0[1]+"\" end=\""+F0[2]+"\" />");
sb.append("\n\t<normf0 beg=\""+normF0[0]+"\" mid=\""+normF0[1]+"\" end=\""+normF0[2]+"\" />");
// for (Sample sample : subSamples.values()) {
// sb.append("\n\t");
// sb.append(sample.toXML());
// }
sb.append("</sample>\n");
return sb.toString();
} |
ec54a812-59b3-4ccb-b99e-89cb54607be0 | public LinkedHashMap<String, Locutor> getLocutors() {
LinkedHashMap<String, Locutor> locutors = new LinkedHashMap<String, Locutor>();
for (Entity entity: this) {
Locutor loc = entity.getLocutor();
if (!locutors.containsKey(loc.getName())) {
locutors.put(loc.getName(), loc);
}
}
return locutors;
} |
bf0a048a-464b-4f52-873b-0a1ddfa0dd02 | public Entity(Locutor loc, Tier tier, Sample sample) {
this.locutor = loc;
this.tier = tier;
this.sample = sample;
} |
98fa1137-5015-469f-9ee7-41859a1df1ce | public Locutor getLocutor() {
return locutor;
} |
ab16f805-2b97-468e-99c9-f97abc56abf7 | public Tier getTier() {
return tier;
} |
a94809c5-1ebf-4d3d-92a6-78d68f178116 | public Sample getSample() {
return sample;
} |
39e35c22-28c0-483c-99b9-0439f7dd2f60 | public String toXML() {
StringBuffer sb = new StringBuffer();
sb.append("\n");
// boolean print = true;
sb.append("<entity loc=\""+locutor.getName()+"\" tier=\""+tier.getName()+"\" sample=\""+sample.getLabel()+"\">");
sb.append(sample.toXML());
sb.append("</entity>\n");
return sb.toString();
} |
2e69b50f-8453-41e2-95e0-ed0c48c3aac6 | public SampleMean(String label) {
this.label = label;
this.childs = new SampleMeans();
this.entities = new Entities();
} |
07de0805-e0c7-40dc-89a1-83dffddec2b8 | public String getLabel() {
return this.label;
} |
9844cea2-f028-4fd0-913e-db0106c7a316 | public void addEntity(Entity entity) {
this.entities.add(entity);
} |
185d6561-58c2-4f2c-828d-5677d1872b28 | public SampleMeans getChilds() {
return childs;
} |
d60eb6bb-b3ea-47d4-8b41-41a3e950622d | public Entities getEntities() {
return entities;
} |
586eca6b-8db3-4b07-b6fe-21abe4fd0e3e | public LinkedHashMap<String, Locutor> getChildLocutors() {
LinkedHashMap<String, Locutor> locutors = new LinkedHashMap<String, Locutor>();
for (SampleMean child: getChilds().values()) {
for (Locutor loc: child.getEntities().getLocutors().values()) {
if (!locutors.containsKey(loc.getName())) {
locutors.put(loc.getName(), loc);
}
}
}
return locutors;
} |
8fcc7e66-3718-4439-acf9-e636609e395d | public float getMeanDuration() {
ArrayList<Float> values = new ArrayList<Float>();
for (Entity entity: entities) {
Sample sample = entity.getSample();
if (sample.getNormDuration()!=Sample.UNDEFINED) {
values.add(sample.getNormDuration());
}
}
return Util.getMean(values);
} |
0921eef6-afc7-4cfd-8ba6-6c5f30ada778 | public float getTotalChildsMeanDuration() {
float total = 0f;
for (SampleMean child: getChilds().values()) {
total += child.getMeanDuration();
}
return total;
} |
b9cee62e-b117-4780-b9dc-f5fc0536d6b7 | public float getMeanF0(int i) {
return getMeanF0(i, null);
} |
eb6dbd3f-430f-4473-9c30-986993e09dbe | public float getMeanF0(int i, Locutor locutor) {
ArrayList<Float> values = new ArrayList<Float>();
String locName = null;
if (locutor!=null) locName = locutor.getName();
for (Entity entity: entities) {
Sample sample = entity.getSample();
if (locName == null || entity.getLocutor().getName().equals(locName)) {
if (sample.getNormF0()[i]!=Sample.UNDEFINED) {
values.add(sample.getNormF0()[i]);
}
}
}
return Util.getMean(values);
} |
308e1e7f-c9a9-43cf-8b00-e3616d454de6 | public String toXML() {
StringBuffer sb = new StringBuffer();
sb.append("\n");
boolean print = true;
// if (!label.contains(":")) {
// if (childs.size()<3) print = false;
// }
if (print) {
sb.append("<samplemean label=\""+label+"\">");
float md = getMeanDuration();
if (md!=0.0f) sb.append("\n\t<duration>"+md+"</duration>");
for (int i=0 ; i<3 ; i++) {
float mf = getMeanF0(i);
if (mf!=0.0f && !"NaN".equals(""+mf)) sb.append("\n\t<f0 i=\""+i+"\">"+mf+"</f0>");
}
if (entities.size()>0) {
sb.append("\n\t<entities quantity=\""+entities.size()+"\">");
if (label.equals("11")) {
for (Entity entity : entities) {
sb.append("\n\t");
sb.append(entity.toXML());
}
}
sb.append("\n\t</entities>");
}
if (childs.size()>0) {
sb.append("\n\t<childs>");
for (SampleMean child : childs.values()) {
sb.append("\n\t");
sb.append(child.toXML());
}
sb.append("\n\t</childs>");
}
sb.append("</samplemean>\n");
}
return sb.toString();
} |
7fa637ab-0956-46a4-8e13-72598ddfa2a1 | public static Sample getContainer (Sample sample, Collection<Sample> samples) {
float start = sample.getStart();
float end = start + sample.getDuration();
for (Sample container: samples) {
float cstart = container.getStart();
float cend = cstart + container.getDuration() + 0.001f;
if (start>=cstart && end<=cend) {
return container;
}
}
return null;
} |
50e50f10-117b-42e3-ae0e-45b9f53787b6 | public static Sample getFirstChild (Sample sample, Collection<Sample> samples) {
float start = sample.getStart();
float end = start + sample.getDuration();
for (Sample child: samples) {
float cstart = child.getStart();
float cend = cstart + child.getDuration();
if (cstart>=start && cend<=end) {
return child;
}
}
return null;
} |
b6cd8377-6387-46f3-a0d5-f02739e8455b | public static float getMean(List<Float> values) {
float mean = 0;
int i = values.size();
float total = 0;
for (float val: values) {
total+=val;
}
mean = total/i;
return mean;
} |
6bbfd79f-882f-475e-ae21-12d639087f7c | public static float getStandardDeviation(List<Float> values) {
double dev = 0;
int i = values.size();
float M = Util.getMean(values);
double sd2 = 0;
for (float val: values) {
float d = val - M;
/**
* TODO : Test with : sd2 += Math.pow(d, 2);
*/
sd2 = Math.pow(d, 2);
}
dev = Math.sqrt(sd2/i);
return new Float(dev).floatValue();
} |
f065c2d0-6fb0-4cc0-8c4d-ff63a3000509 | public static float getStandardizeValue(float X, float M, float dev) {
float sv = (X-M)/dev ;
return sv;
} |
38d69ebb-a47e-4fd9-91d5-3ab14b96598c | public static float getStandardizeValue(float X, float M) {
return ( X/M );
} |
a92675c5-f7e0-40c1-90d5-562b11c6449e | public static String cleanString(String str) {
Transliterator accentsconverter = Transliterator.getInstance("Latin; NFD; [:Nonspacing Mark:] Remove; NFC;");
str = accentsconverter.transliterate(str);
//the character ? seems to not be changed to d by the transliterate function
StringBuffer cleanedStr = new StringBuffer(str.trim());
// delete special character
for(int i = 0; i < cleanedStr.length(); i++) {
char c = cleanedStr.charAt(i);
if(c == ' ') {
if (i > 0 && cleanedStr.charAt(i - 1) == '-') {
cleanedStr.deleteCharAt(i--);
}
else {
c = '-';
cleanedStr.setCharAt(i, c);
}
continue;
}
if(!(Character.isLetterOrDigit(c) || c == '-')) {
cleanedStr.deleteCharAt(i--);
continue;
}
if(i > 0 && c == '-' && cleanedStr.charAt(i-1) == '-')
cleanedStr.deleteCharAt(i--);
}
return cleanedStr.toString().toLowerCase();
} |
3907ba2e-3cd4-4f30-81e2-72735270f649 | public TreeBuilder(int endInterval) {
this.endInterval = endInterval;
} |
e4761255-b4aa-4f78-aad7-285b375caf5d | public Node buildTree(){
return buildSubTree(0,endInterval);
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.