Filosoft / vabamorf

Eesti keele morfanalüsaator
Other
24 stars 14 forks source link

JSON output sometimes not compatible with Python's json.tool #4

Closed Kaljurand closed 10 years ago

Kaljurand commented 10 years ago

A recommended way of pretty-printing JSON files is Python's json.tool (see e.g. http://stackoverflow.com/questions/352098/how-can-i-pretty-print-json). The Vabamorf commandline clients sometimes produce output that is not compatible with json.tool (possibly because it's incompatible with JSON).

To demonstrate the issue:

$ git clone -b examples_cmdline https://github.com/Kaljurand/vabamorf
$ cd vabamorf/doc/
$ git checkout b8bb714
$ make test_json 
find . -name "*.json" | while read json; do echo "$json"; python -mjson.tool $json > /dev/null; done
...
./json/etana/ex2_analyze_phonetic.json
Expecting property name: line 2 column 2 (char 3)
...
./json/etana/ex1_analyze_phonetic.json
Expecting property name: line 2 column 2 (char 3)
...
./json/etana/ex1_analyze.json
Expecting property name: line 2 column 2 (char 3)
...

The offending files start with:

{ {
PRR24 commented 10 years ago

Could you please provide the (reduced) input file with steps to repro. Thanks.

Kaljurand commented 10 years ago
$ echo '{"sentences":[{"text":"text"}]}' | python -mjson.tool | etana analyze -lex ../dct/ | python -mjson.tool
Expecting property name: line 2 column 2 (char 3)

The first call to Python succeeds, the 2nd does not...

PRR24 commented 10 years ago

The sample provided does not have a proper input file structure. It does not have paragraphs neither words. The cmdline version used does not threat mis-structured data correctly. New version is more reliable on that sense. Please retry and confirm success.

Kaljurand commented 10 years ago

I'm getting compilation errors with the latest version (let me know if I should open a new issue and provide more details):

$ make -f Makefile.etana 
g++ -O2 -DNDEBUG -Wall -std=gnu++0x -fdata-sections -ffunction-sections -Wl,--gc-sections -o etana ../../etana/*.cpp ../../../../lib/proof/*.cpp ../../../../lib/etana/*.cpp ../../../lib/*.cpp ../../../../lib/fsc/*.cpp -pthread
../../etana/etana.cpp: In member function ‘virtual void CMyJSONReader::OnValReadStart(const CFSAString&)’:
../../etana/etana.cpp:34:46: error: ‘KeyMatch’ was not declared in this scope
   } else if (KeyMatch(szKey, "/paragraphs/%d")) {
                                              ^
../../etana/etana.cpp: In member function ‘virtual void CMyJSONReader::OnValReadEnd(const CFSAString&, CFSVar&)’:
../../etana/etana.cpp:63:46: error: ‘KeyMatch’ was not declared in this scope
   } else if (KeyMatch(szKey, "/paragraphs/%d")) {
                                              ^
../../../../lib/proof/suggestor.cpp:9:44: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
 static const CFSWString szInsertLettersBeg=L"KPSTVLMRAHNEJIO\x00dc"L"DFUB\x00d5"L"G";
                                            ^
../../../../lib/proof/suggestor.cpp:9:68: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
 static const CFSWString szInsertLettersBeg=L"KPSTVLMRAHNEJIO\x00dc"L"DFUB\x00d5"L"G";
                                                                    ^
../../../../lib/proof/suggestor.cpp:10:41: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
 static const CFSWString szInsertLetters=L"AEISTLUNKMODRVGHJP\x00c4\x00d5"L"B\x00dc\x00d6";
                                         ^
../../../../lib/etana/komp.cpp: In member function ‘int MORF0::leia_algvorm(KOMPONENT*)’:
../../../../lib/etana/komp.cpp:468:12: warning: unused variable ‘idx’ [-Wunused-variable]
     AVTIDX idx;
            ^
../../../../lib/etana/mrf-gen.cpp: In member function ‘bool ETMRFAS::GeneSTV(MRFTULEMUSED*, const FSXSTRING*, const FSXSTRING*, const FSXSTRING*, const FSXSTRING*, int, int, const FSXSTRING*)’:
../../../../lib/etana/mrf-gen.cpp:800:12: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wparentheses]
         if ( sl->Find(sl1) == -1) // see sõnaliik pole siin lubatud
            ^
make: *** [all] Error 1
PRR24 commented 10 years ago

My apologies, push error. Please retry.

Kaljurand commented 10 years ago

Seems to be fixed. Thanks!