Skip to content

Commit c642dd6

Browse files
committed
Extracting formatted annotations
1 parent 9401937 commit c642dd6

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

java/br/unb/biologiaanimal/edf/EDF.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,14 @@ public void toCsv(String filePath)
218218
}
219219

220220
// TODO Read annotations
221+
/**
222+
* Gets a list of the annotations on the EDF file, lest there are
223+
* annotations.
224+
* @return An array containing one annotation for each entry
225+
* @throws NoSuchFieldException
226+
*/
221227
public String[] getAnnotations()
228+
throws NoSuchFieldException
222229
{
223230
return reader.getAnnotations();
224231
}

java/br/unb/biologiaanimal/edf/EDFReader.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,50 @@ private long[] getLimits(String param)
284284
}
285285

286286
// TODO Get annotations
287+
/**
288+
* Gets a list of the annotations on the EDF file, lest there are
289+
* annotations.
290+
* @return An array containing one annotation for each entry
291+
* @throws NoSuchFieldException
292+
*/
287293
public String[] getAnnotations()
294+
throws NoSuchFieldException
295+
{
296+
int annotationsChannel = getAnnotationsChannelIndex();
297+
298+
if (annotationsChannel < 0) {
299+
throw new NoSuchFieldException();
300+
}
301+
302+
return getRawNotes().split("\n");
303+
}
304+
305+
private String getRawNotes()
288306
{
289-
throw new UnsupportedOperationException();
307+
byte[] raw = this.getRecord("EDF Annotations");
308+
String outlet = "";
309+
boolean inside = false;
310+
311+
for (int i = 0; i < raw.length; ++i)
312+
{
313+
if (inside) {
314+
if (raw[i] == 0) {
315+
inside = false;
316+
outlet += "\n";
317+
}
318+
else {
319+
byte it = raw[i];
320+
boolean fact = (it == (byte) 20) || (it == (byte) 21);
321+
raw[i] = (fact)? (byte) ' ' : it;
322+
outlet += (char) raw[i];
323+
}
324+
}
325+
else if (raw[i] == '+' || raw[i] == '-') {
326+
inside = true;
327+
outlet += (char) raw[i];
328+
}
329+
}
330+
331+
return outlet;
290332
}
291333
}

target/edf.jar

282 Bytes
Binary file not shown.

test/br/unb/biologiaanimal/test/Run.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ public static void main(String[] args) {
2828
allLabels += (i+1) + ". " + labels[i] + "\n";
2929
}
3030
System.out.println(allLabels);
31-
System.out.println("--- # Let's write something");
32-
System.out.println("-- " + edf.sayHi());
33-
System.out.println("-- Writing to ASCII format");
34-
System.out.println("-- + Single channel");
35-
try { edf.toSingleChannelAscii("data\\edf\\HCT\\ECG.ascii", "ECG"); }
36-
catch (Exception any) { System.out.println(any); }
37-
System.out.println("-- + All channels");
38-
try { edf.toAscii("data\\edf\\HCT-4-23.ascii"); }
39-
catch (Exception any) { System.out.println(any); }
40-
System.out.println("-- + To CSV");
41-
try { edf.toCsv("data\\edf\\HCT-4-23.java.ascii"); }
42-
catch (Exception any) { System.out.println(any); }
4331
System.out.println("-- + Getting annotations");
4432
try
4533
{
@@ -54,6 +42,19 @@ public static void main(String[] args) {
5442
System.out.println(any);
5543
}
5644

45+
System.out.println("--- # Let's write something");
46+
System.out.println("-- " + edf.sayHi());
47+
System.out.println("-- Writing to ASCII format");
48+
System.out.println("-- + Single channel");
49+
try { edf.toSingleChannelAscii("data\\edf\\HCT\\ECG.ascii", "ECG"); }
50+
catch (Exception any) { System.out.println(any); }
51+
System.out.println("-- + All channels");
52+
try { edf.toAscii("data\\edf\\HCT-4-23.ascii"); }
53+
catch (Exception any) { System.out.println(any); }
54+
System.out.println("-- + To CSV");
55+
try { edf.toCsv("data\\edf\\HCT-4-23.java.ascii"); }
56+
catch (Exception any) { System.out.println(any); }
57+
5758
System.out.println("...");
5859
}
5960
}

0 commit comments

Comments
 (0)