for (final MLArray vocArrItem : vocArr) { final MLChar vocChar = (MLChar) vocArrItem; final String vocString = vocChar.getString(0); if (filter && this.keepIndex.contains(index)) { this.voc.put(vocIndex, vocString);
public static String[] readStringsArrayFromMat(Path matFile, String stringsArrayName) throws IOException { Objects.requireNonNull(matFile, "mat file is null"); Objects.requireNonNull(stringsArrayName, "strings array name is null"); MatFileReader matFileReader = new MatFileReader(); Map<String, MLArray> matFileContent = matFileReader.read(matFile.toFile()); MLCell stringsArray = (MLCell) matFileContent.get(stringsArrayName); String[] strings = new String[stringsArray.getN()]; for (int i = 0; i < stringsArray.getN(); i++) { strings[i] = ((MLChar) stringsArray.get(0, i)).getString(0); } return strings; }
@Test public void testMLCharStringArray() { String[] expected = new String[]{"a", "quick", "brown", "fox"}; MLChar mlchar = new MLChar("array", expected); assertEquals(expected[0], mlchar.getString(0)); assertEquals(expected[1], mlchar.getString(1)); assertEquals(expected[2], mlchar.getString(2)); assertEquals(expected[3], mlchar.getString(3)); }
@Test public void testCharArray2() { MLChar actual = (MLChar) MLArrayQuery.q(array, "SPM.xCon(1,2).name"); assertEquals("bike", actual.getString(0)); }
@Test public void testParsingSimpleSingleTextUnmodifiedMCOS() throws IOException { File file = fileFromStream("/mcos/simplesingletext_unmodified.mat"); MatFileReader reader = new MatFileReader(file); Map<String, MLArray> content = reader.getContent(); assertThat(content.size(), equalTo(1)); MLObject obj = (MLObject) content.get("obj"); assertThat(obj, notNullValue()); assertThat(obj.getName(), equalTo("obj")); assertThat(obj.getClassName(), equalTo("SimpleSingleText")); Map<String, MLArray> fields = obj.getFields(0); assertThat(fields.size(), equalTo(1)); MLChar field = (MLChar) fields.get("test_text"); assertThat(field.getString(0), equalTo("Default text")); }
@Test public void testUTF() throws IOException { // read array form file MatFileReader mfr = new MatFileReader(getTestFile("utf.mat")); Map<String, MLArray> map = mfr.getContent(); MLStructure val = (MLStructure) map.get("val"); // extract each utf MLChar utf8 = (MLChar) val.getField("utf8"); MLChar utf16 = (MLChar) val.getField("utf16"); MLChar utf32 = (MLChar) val.getField("utf32"); // assert the content String expected = "\uD841\uDF0E"; Assert.assertEquals(expected, utf8.getString(0)); Assert.assertEquals(expected, utf16.getString(0)); Assert.assertEquals(expected, utf32.getString(0)); }
@Test public void testMLCharUnicode() throws Exception { // array name String name = "chararr"; // file name in which array will be storred String fileName = "mlcharUTF.mat"; // create MLChar array of a name "chararr" containig one // string value "dummy" MLChar mlChar = new MLChar(name, new String[]{"\u017C\u00F3\u0142w", "\u017C\u00F3\u0142i"}); MatFileWriter writer = new MatFileWriter(); writer.write(getTempFile(fileName), Arrays.asList((MLArray) mlChar)); MatFileReader reader = new MatFileReader(getTempFile(fileName)); MLChar mlChar2 = (MLChar) reader.getMLArray(name); assertEquals("\u017C\u00F3\u0142w", mlChar.getString(0)); assertEquals("\u017C\u00F3\u0142w", mlChar2.getString(0)); assertEquals("\u017C\u00F3\u0142i", mlChar2.getString(1)); }
@Test public void testCell() { MLChar actual = (MLChar) MLArrayQuery.q(array, "SPM.Sess(1,1).U(1,1).name"); assertEquals("aquarium", actual.getString(0)); String str = (String) MLArrayQuery.q(array, "SPM.Sess(1,1).U(1,2).name(1)"); assertEquals("bike", str); }
Map<String, MLArray> dataO = data.getFields(0); assertThat(dataO.size(), equalTo(10)); assertThat(((MLChar) dataO.get("function_name")).getString(0), equalTo("quad_fcn_subtype")); assertThat(((MLChar) dataO.get("function_inputs")).getString(0), equalTo("c,a,b:{x:real|(a=0 => x /= 0) AND (a /= 0 => (x^2) - 4*a*c >= 0)}")); assertThat(((MLDouble) dataO.get("open")).get(0), equalTo(0.0)); assertThat(((MLDouble) dataO.get("fig")).getSize(), equalTo(0)); // This field should just exist, but be empty! Map<String, MLArray> cellO = cells.getFields(0); assertThat(((MLChar) cellO.get("cond_text")).getString(0), equalTo("a == 0")); assertThat(((MLChar) cells.getFields(1).get("cond_text")).getString(0), equalTo("a ~= 0"));
assertThat(timeInfo.getFieldNames(), hasItem("Units")); MLChar timeInfoUnits = (MLChar) timeInfo.getField("Units"); assertThat(timeInfoUnits.getString(0), equalTo("seconds"));
result = mlchar.getString( m );
result = mlchar.getString( m );
valueS = mlChar.getString(0); assertEquals("MLChar value getter", "dummy", valueS);
result = mlchar.getChar(m, n); } else if (m > -1) { result = mlchar.getString(m); } else { result = mlchar;
result = mlchar.getChar(m, n); } else if (m > -1) { result = mlchar.getString(m); } else { result = mlchar;