Kyungdon/yamlmatlab

Fails to parse bulleted list

Closed this issue · 9 comments

What steps will reproduce the problem?
1. I am using the following config file:
=== test.yaml ===
List:
- Item1
- Item2

2. I read the config file using the following command:
>> config = ReadYaml('test.yaml')

What is the expected output? What do you see instead?
I expect to see a list populated with data, instead I get this:

config = 

    List: []

What version of the product are you using? On what operating system?
I'm using version 2.2 on Ubuntu 10.04

Original issue reported on code.google.com by chris.fl...@gmail.com on 5 May 2011 at 8:32

Hello, 
I tried the same piece of code on the newest Debian and the result was

>> config = ReadYaml(fname)
config = 

    List: {'Item1'  'Item2'}

Hence, it seems that there is some incompatibility within linux operating 
systems.

What version of matlab do you have? Paste here the output of ver command, 
please.

This package makes use of jar library snakeyaml, and you can easily detect 
whether the problem lies in the library:
First, open ReadYaml and put brakepoint on line 37 then run the same code as 
before. 
Now, the yml and yymlobj variables should look like as follows:

>> yml 
yml =

List:
- Item1
- Item2

K>> jymlobj = yamlreader.load(yml)

jymlobj =

{List=[Item1, Item2]}

Original comment by JirkaCig...@gmail.com on 6 May 2011 at 6:23

Hello,

>> What version of matlab do you have? Paste here the output of ver command, 
please.
MATLAB Version 7.10.0.499 (R2010a)
Operating System: Linux 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 
2011 i686
Java VM Version: Java 1.6.0_12-b04 with Sun Microsystems Inc. Java HotSpot(TM) 
Client VM mixed mode

I tried printing out jymlobj and that part seems to be working:
K>> jymlobj = yamlreader.load(yml)

jymlobj =

{List=[Item1, Item2]}

The problem seems to be in Hash2Struct function.
K>> str2num(d.toString);   

ans =

     []

K>> d

d =

[Item1, Item2]

I replaced the offending line with the following, it seems to do something.

K>> char(d.toArray())

ans =

Item1
Item2

I'm not sure what data type I should try to convert to through... I'm getting 
this for the end result now:

K>> config

config = 

    List: [2x5 char]

Original comment by chris.fl...@gmail.com on 6 May 2011 at 4:13

Unfortunately, I cannot find the offending line of code in Hash2Struct. You 
wrote you use version 0.2.2 therefore please have a look at 
http://code.google.com/p/yamlmatlab/source/browse/tags/0.2.2/Hash2Struct.m and 
write here which part of the code seems to be problematic.

Anyway, the resulting variable config should look like 
config = 

    List: {'Item1'  'Item2'}
which is a Matlab structure with one field List which value is 1x2 cell of 
chars.


Original comment by JirkaCig...@gmail.com on 6 May 2011 at 5:00

  • Added labels: Priority-High
  • Removed labels: Priority-Medium
Thanks for the response. Well it wasn't working because I was being an idiot. I 
had been experimenting with snakeyaml before and had a pre-existing 
Hash2Struct.m file in my directory. :P. Srry. It seems to work fine with the 
test file.

I tried running yamlmatlab on my actual config file and seem to be running into 
a completely different problem now. Here is the yaml file I'm trying to parse:
=== test.yaml ===
sensors:
    - class: Compass
      tiltSigma: 0.2
      headingSigma: 0.5
      Hz: 20
      translation: [1,1,1]
      rotationaxis: [1, 0, 0, 0]
    - class: DepthSensor
      whiteSigma: 0.1
      translation: [0.1, 0.2, 0.3]

And am getting this error:
??? Subscripted assignment between dissimilar structures.

Error in ==> Hash2Struct at 88
                            Data.(field)(hh+1)=Hash2Struct(hm);

Error in ==> ReadYaml at 37
Data = Hash2Struct(jymlobj);

Error in ==> dvlAlign at 7
config = ReadYaml('test.yaml') %'../../config/sunfish/sunfish.yaml');

Seems like this might be an actual issue now. Currently the Matlab data 
structure being generated is 

sensors (struct)
  Compass (struct)

When it crashes, maybe it should be something like this?
sensors (struct)
  [Compass(struct), DepthSensor(struct)]

Original comment by chris.fl...@gmail.com on 6 May 2011 at 5:28

Unfortunately, this kind of structure is not, to my knowledge, representable in 
a matlab struct since if you have an array of structs (as you specified in YAML 
file) all structs must have the same fields.

For example your test.yaml contains field sensors, there is array indicator 
"-". Each item of this array contains stucture
-the first one with fields class, tiltSigma,Hz, translation, rotationaxis
-the second one only class, whiteSigma,translation

and now, try to merge these structs to an array :-) 

For example

>> a.test='a'

a = 

    test: 'a'

>> b.x ='b'

b = 

    x: 'b'

>> [a, b]
??? Error using ==> horzcat
CAT arguments are not consistent in structure field names.

>> [a;b]
??? Error using ==> vertcat
CAT arguments are not consistent in structure field names.

>> x(1)=a

x = 

    test: 'a'

>> x(2)=b
??? Subscripted assignment between dissimilar structures.


Moreover, the structures which are to be merged must have the same order of 
fields :( 


We faced to the same problem in our project and finally, we had to have the 
same structure of structures, unfortunately.
So I'd suggest you to do the same if possible.

Original comment by JirkaCig...@gmail.com on 6 May 2011 at 5:52

Original comment by JirkaCig...@gmail.com on 6 May 2011 at 5:53

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect
after all, We decided to implement suppot for the YAML file structure you have.

So if you download version 0.3.0, then you should get the following
>> config = ReadYaml('test2.yaml')

config = 

    sensors: {[1x1 struct]  [1x1 struct]}

>> config.sensors{1}

ans = 

           class: 'Compass'
       tiltSigma: 0.2000
    headingSigma: 0.5000
              Hz: 20
     translation: [1 1 1]
    rotationaxis: [1 0 0 0]

>> config.sensors{2}

ans = 

          class: 'DepthSensor'
     whiteSigma: 0.1000
    translation: [0.1000 0.2000 0.3000]

Original comment by JirkaCig...@gmail.com on 8 May 2011 at 8:36

Thanks! This works great now, I will include it in my project.

Original comment by chris.fl...@gmail.com on 9 May 2011 at 4:14

Original comment by JirkaCig...@gmail.com on 9 May 2011 at 9:55

  • Changed state: Done