diff --git a/.github/workflows/foliatest.yml b/.github/workflows/foliatest.yml index 845c9e9..5c67eee 100644 --- a/.github/workflows/foliatest.yml +++ b/.github/workflows/foliatest.yml @@ -47,11 +47,13 @@ jobs: - uses: LanguageMachines/ticcactions/cpp-submodule-build@v1 with: + branch: ${{ github.ref_name }} module: ticcutils - uses: LanguageMachines/ticcactions/cpp-submodule-build@v1 with: module: libfolia + branch: ${{ github.ref_name }} - name: Static Code-check if: ${{ env.action_status == '' }} diff --git a/configure.ac b/configure.ac index 92f0fa2..992fc77 100644 --- a/configure.ac +++ b/configure.ac @@ -46,7 +46,7 @@ PKG_CHECK_MODULES([ICU], [icu-uc >= 50 icu-io] ) CXXFLAGS="$CXXFLAGS $ICU_CFLAGS" LIBS="$ICU_LIBS $LIBS" -PKG_CHECK_MODULES([ticcutils], [ticcutils >= 0.29] ) +PKG_CHECK_MODULES([ticcutils], [ticcutils >= 0.36] ) CXXFLAGS="$CXXFLAGS $ticcutils_CFLAGS" LIBS="$LIBS $ticcutils_LIBS" diff --git a/src/edit_tests.cxx b/src/edit_tests.cxx index 26f01da..bbb3487 100644 --- a/src/edit_tests.cxx +++ b/src/edit_tests.cxx @@ -93,8 +93,11 @@ void edit_test001a( ){ // attribute check assertTrue( s->index(0)->annotator() == "testscript" ); +#if FOLIA_INT_VERSION < 221 assertTrue( s->index(2)->annotatortype() == AUTO ); - +#else + assertTrue( s->index(2)->annotatortype() == AnnotatorType::AUTO ); +#endif // adition to paragraph correct? assertEqual( p->size(), (tmp+1) ); assertTrue( p->rindex(0) == s ); @@ -347,7 +350,11 @@ void edit_test005a( ){ assertTrue( p->isinstance() ); std::vector alt3; +#if FOLIA_INT_VERSION < 221 assertNoThrow( alt3 = w->alternatives(PosAnnotation_t, pos_set) ); +#else + assertNoThrow( alt3 = w->alternatives(ElementType::PosAnnotation_t, pos_set) ); +#endif assertEqual( alt3.size(), 1 ); assertEqual( alt[0] , alt3[0] ); @@ -544,7 +551,7 @@ void edit_test011(){ f = new Feature( getArgs("subset='function', class='plural'"), &editDoc ); m->append( f ); assertTrue( len(l) == 2 ); // 2 morphemes - assertTrue( isinstance( l->index(0), Morpheme_t ) ); + assertTrue( l->index(0)->isinstance() ); assertTrue( l->index(0)->text() == "handschrift" ); assertTrue( l->index(0)->feat("type") == "stem" ); assertTrue( l->index(0)->feat("function") == "lexical" ); diff --git a/src/engine_tests.cxx b/src/engine_tests.cxx index 4cc58bd..d222ad4 100644 --- a/src/engine_tests.cxx +++ b/src/engine_tests.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "libxml/tree.h" #include "ticcutils/StringOps.h" @@ -286,7 +287,7 @@ void engine_test004(){ } } -void engine_test005(){ +void engine_test005a(){ startTestSerie( " enumerate a document on xml_element nodes " ); Engine proc; // proc.set_debug(true); @@ -308,6 +309,35 @@ void engine_test005(){ } } +#if FOLIA_INT_VERSION >= 221 +void engine_test005b(){ + startTestSerie( " enumerate a document on xml_element nodes with debugging" ); + Engine proc; + Document d("debug='PARSING|SERIALIZE'"); + ofstream os( "/tmp/foliaengine.dbg" ); + TiCC::LogStream ds( os ); + ds.set_level( LogHeavy ); + proc.set_debug(true); + proc.set_dbg_stream( &ds ); + assertNoThrow( proc.init_doc( "tests/example.xml" ) ); + if ( proc.ok() ){ + xml_tree *result = proc.create_simple_tree("tests/example.xml"); + ofstream os( "/tmp/enum.tree" ); + print( os, result ); + delete result; + int stat = system( "diff /tmp/enum.tree tests/enum.tree.216.ok" ); + assertMessage( "/tmp/enum.tree tests/enum.tree.216.ok differ!", + (stat == 0) ); + } + size_t size = std::filesystem::file_size("/tmp/foliatest.dbg"); + assertTrue( size > 5000 ); +} +#else +void engine_test005b(){ + // noop +} +#endif + void engine_test006a(){ startTestSerie( " enumerate a document on text node parents" ); TextEngine proc; diff --git a/src/foliapy_tests.cxx b/src/foliapy_tests.cxx index f5f0173..e16911d 100644 --- a/src/foliapy_tests.cxx +++ b/src/foliapy_tests.cxx @@ -97,7 +97,7 @@ void Test_E001_Tokens_Structure(){ { startTestSerie("Simple Token & Structure Test - First word"); FoliaElement *w = words[0]; - assertTrue( w->isinstance( Word_t ) ); + assertTrue( w->isinstance() ); assertEqual( w->id(), "example.p.1.s.1.w.1" ); assertEqual( w->text(), "Hello" ); assertEqual( str(w), "Hello" ); @@ -114,7 +114,7 @@ void Test_E001_Tokens_Structure(){ startTestSerie( "Simple Token & Structure Test - Sentence" ); //grab second sentence FoliaElement *s = doc.sentences(1); - assertTrue( isinstance( s, Sentence_t) ); + assertTrue( s->isinstance() ); assertEqual( s->id(), "example.p.1.s.2" ); assertFalse( s->hastext() ); //no explicit text assertEqual( str(s), "This is an example." ); @@ -123,7 +123,7 @@ void Test_E001_Tokens_Structure(){ startTestSerie( "Simple Token & Structure Test - Index" ); // rab something using the index FoliaElement *w = doc["example.p.1.s.1.w.1"]; - assertTrue( isinstance( w, Word_t ) ); + assertTrue( w->isinstance() ); assertEqual( doc["example.p.1.s.1.w.1"], doc.index("example.p.1.s.1.w.1") ); assertEqual( w->id(), "example.p.1.s.1.w.1" ); @@ -132,11 +132,18 @@ void Test_E001_Tokens_Structure(){ { startTestSerie( "Simple Token & Structure Test - Declarations" ); assertTrue( doc.declared(AnnotationType::TOKEN) ); - assertTrue( doc.declared(Word_t) ); // same as above, resolves automatically assertTrue( doc.declared(AnnotationType::TEXT) ); +#if FOLIA_INT_VERSION < 221 + assertTrue( doc.declared(Word_t) ); // same as above, resolves automatically assertTrue( doc.declared(TextContent_t) ); //same as above, resolves automatically assertTrue( doc.declared(Sentence_t) ); assertTrue( doc.declared(Paragraph_t) ); +#else + assertTrue( doc.declared(ElementType::Word_t) ); // same as above, resolves automatically + assertTrue( doc.declared(ElementType::TextContent_t) ); //same as above, resolves automatically + assertTrue( doc.declared(ElementType::Sentence_t) ); + assertTrue( doc.declared(ElementType::Paragraph_t) ); +#endif } } @@ -286,13 +293,25 @@ void Test_Provenance(){ assertEqual((*provenance)["p0"]->name(), "ucto" ); assertEqual((*provenance)["p0.1"]->name(), "libfolia"); assertEqual((*provenance)["p1"]->name(), "frog"); +#if FOLIA_INT_VERSION < 221 assertEqual((*provenance)["p1"]->type(), AUTO ); +#else + assertEqual((*provenance)["p1"]->type(), AnnotatorType::AUTO ); +#endif assertEqual(provenance->index("p1")->version(), "0.16"); assertEqual((*provenance)["p1.0"]->name(), "libfolia"); +#if FOLIA_INT_VERSION < 221 assertEqual((*provenance)["p1.0"]->type(), GENERATOR ); +#else + assertEqual((*provenance)["p1.0"]->type(), AnnotatorType::GENERATOR ); +#endif assertEqual((*provenance)["p1.0"]->name(), "libfolia"); assertEqual((*provenance)["p2.1"]->name(), "proycon"); +#if FOLIA_INT_VERSION < 221 assertEqual((*provenance)["p2.1"]->type(), MANUAL ); +#else + assertEqual((*provenance)["p2.1"]->type(), AnnotatorType::MANUAL ); +#endif auto annotators = doc.get_annotators( AnnotationType::POS, "http://ilk.uvt.nl/folia/sets/frog-mbpos-cgn" ); assertEqual(len(annotators), 3 ); @@ -303,9 +322,17 @@ void Test_Provenance(){ // let's see if we got the right ones: assertEqual( processors[0]->id(), "p1.1" ); assertEqual( processors[0]->name(), "mbpos" ); +#if FOLIA_INT_VERSION < 221 assertEqual( processors[0]->type(), AUTO ); +#else + assertEqual( processors[0]->type(), AnnotatorType::AUTO ); +#endif assertEqual( processors[1]->name(), "proycon"); +#if FOLIA_INT_VERSION < 221 assertEqual( processors[1]->type(), MANUAL ); +#else + assertEqual( processors[1]->type(), AnnotatorType::MANUAL ); +#endif } { startTestSerie( "Provenance - Annotation sanity check" ); @@ -315,20 +342,32 @@ void Test_Provenance(){ auto proc = doc.get_processor( pid ); assertEqual( proc->id(), "p1.1" ); assertEqual( proc->name(), "mbpos" ); +#if FOLIA_INT_VERSION < 221 assertEqual( proc->type(), AUTO ); +#else + assertEqual( proc->type(), AnnotatorType::AUTO ); +#endif // The old annotator attribute can also still be used and refers to the // processor name (for backward API compatibility) assertEqual( proc->annotator(), "mbpos" ); // The old annotatortype attribute can also still be used and refers // to the processor type: +#if FOLIA_INT_VERSION < 221 assertEqual( proc->annotatortype(), AUTO ); +#else + assertEqual( proc->annotatortype(), AnnotatorType::AUTO ); +#endif word = doc["untitled.p.1.s.1.w.2"]; pid = word->annotation()->processor(); assertEqual( pid, "p2.1" ); proc = doc.get_processor( pid ); assertEqual( proc->id(), "p2.1" ); assertEqual( proc->name(), "proycon" ); +#if FOLIA_INT_VERSION < 221 assertEqual( proc->type(), MANUAL ); +#else + assertEqual( proc->type(), AnnotatorType::MANUAL ); +#endif } { startTestSerie("Provenance - Checking default/implicit processor/annotator" ); @@ -337,7 +376,11 @@ void Test_Provenance(){ auto proc = doc.get_processor( pid ); assertEqual( proc->id(), "p1.2" ); assertEqual( proc->name(), "mblem" ); +#if FOLIA_INT_VERSION < 221 assertEqual( proc->type(), AUTO ); +#else + assertEqual( proc->type(), AnnotatorType::AUTO ); +#endif // The old annotator attribute can also still be used and refers to // the processor name assertEqual( proc->annotator(), "mblem"); diff --git a/src/foliatest.cxx b/src/foliatest.cxx index 86f8deb..f392b8e 100644 --- a/src/foliatest.cxx +++ b/src/foliatest.cxx @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include "libxml/tree.h" @@ -148,7 +149,7 @@ void test0() { void test1() { startTestSerie( " Test lezen van een FoLiA file " ); Document d; - assertNoThrow( d.read_from_file( "tests/example.xml" ) ); + assertNoThrow( d.read_from_file("tests/example.xml") ); assertNoThrow( d.save( "/tmp/example.xml" ) ); int stat = system( "./tests/foliadiff.sh /tmp/example.xml tests/example.xml" ); assertMessage( "/tmp/example.xml tests/example.xml differ!", @@ -215,6 +216,28 @@ void test1f() { (stat == 0) ); } +#if FOLIA_INT_VERSION >= 221 +void test1g() { + startTestSerie( " Test testing document debugging " ); + Document d("debug='PARSING|SERIALIZE'"); + ofstream os( "/tmp/foliatest.dbg" ); + TiCC::LogStream ds( os ); + ds.set_level( LogHeavy ); + d.set_dbg_stream( &ds ); + assertNoThrow( d.read_from_file("tests/example.xml") ); + assertNoThrow( d.save( "/tmp/example.xml" ) ); + int stat = system( "./tests/foliadiff.sh /tmp/example.xml tests/example.xml" ); + assertMessage( "/tmp/example.xml tests/example.xml differ!", + (stat == 0) ); + size_t size = std::filesystem::file_size("/tmp/foliatest.dbg"); + assertTrue( size > 5000 ); +} +#else +void test1g() { + // noop +} +#endif + void test2() { startTestSerie( " Test lezen van een FoLiA string " ); string s; @@ -509,7 +532,8 @@ extern void engine_test002b(); extern void engine_test002c(); extern void engine_test003(); extern void engine_test004(); -extern void engine_test005(); +extern void engine_test005a(); +extern void engine_test005b(); extern void engine_test006a(); extern void engine_test006b(); extern void engine_test006c(); @@ -797,7 +821,7 @@ void correction_test002(){ assertEqual( s->text(), "De site staat online ." ); // incorrection() test, check if newly added word correctly reports being part of a correction FoliaElement *w = corDoc.index(corDoc.id() + ".s.1.w.4-5"); - assertTrue( isinstance(w->incorrection(), Correction_t) ); + assertTrue( w->incorrection()->isinstance() ); //incorrection return the correction the word is part of, or None if not part of a correction, assertEqual( s->xmlstring(), "Desitestaatonlineonline." ); } @@ -880,8 +904,11 @@ void correction_test005(){ assertEqual( w->annotation()->suggestions(0)->text(), "stippellijn" ); assertEqual( w->annotation()->getNew()->text(), "stippellijn" ); assertEqual( w->annotation()->annotator(), "John Doe" ); +#if FOLIA_INT_VERSION < 221 assertEqual( w->annotation()->annotatortype(), MANUAL ); - +#else + assertEqual( w->annotation()->annotatortype(), AnnotatorType::MANUAL ); +#endif assertEqual( w->xmlstring(), "stippellijnstippellijnstippelijn" ); delete corDoc; } @@ -1103,8 +1130,13 @@ void query_test002(){ void query_test003(){ startTestSerie( " Find Words by annotation " ); vector words = { "de", "historisch", "wetenschap", "worden" }; +#if FOLIA_INT_VERSION < 221 vector >matches = qDoc.findwords( Pattern( words, LemmaAnnotation_t ) ); +#else + vector >matches = qDoc.findwords( Pattern( words, + ElementType::LemmaAnnotation_t ) ); +#endif assertEqual( matches.size(), 1 ); assertEqual( len(matches[0]), 4 ); @@ -1117,7 +1149,12 @@ void query_test003(){ void query_test004(){ startTestSerie( " Find Words using multiple patterns " ); Pattern p1( { "de", "historische", "*", "wordt" } ); +#if FOLIA_INT_VERSION < 221 Pattern p2( { "de", "historisch", "wetenschap", "worden" }, LemmaAnnotation_t ); +#else + Pattern p2( { "de", "historisch", "wetenschap", "worden" }, + ElementType::LemmaAnnotation_t ); +#endif list l; l.push_back( p1 ); l.push_back( p2 ); @@ -1244,8 +1281,13 @@ void query_test010b(){ void query_test011(){ startTestSerie( " Find Words by non existing annotation " ); vector words = { "bli", "bla", "blu" }; +#if FOLIA_INT_VERSION < 221 vector >matches = qDoc.findwords( Pattern(words, SenseAnnotation_t ) ); +#else + vector >matches = qDoc.findwords( Pattern(words, + ElementType::SenseAnnotation_t ) ); +#endif assertEqual( matches.size(), 0 ); } @@ -1398,6 +1440,7 @@ int main( int argc, char* argv[] ){ test1d(); test1e(); test1f(); + test1g(); test2(); test3(); test4(); @@ -1636,7 +1679,8 @@ int main( int argc, char* argv[] ){ engine_test002c(); engine_test003(); engine_test004(); - engine_test005(); + engine_test005a(); + engine_test005b(); engine_test006a(); engine_test006b(); engine_test006c(); diff --git a/src/sanity_tests.cxx b/src/sanity_tests.cxx index 5f5aab6..9d93e51 100644 --- a/src/sanity_tests.cxx +++ b/src/sanity_tests.cxx @@ -43,6 +43,7 @@ #include "ticcutils/XMLtools.h" #include "libfolia/folia.h" #include "ticcutils/FileUtils.h" +using TiCC::operator<<; // Essential to have this BEFORE include UnitTest.h #include "ticcutils/UnitTest.h" #include "ticcutils/CommandLine.h" @@ -51,7 +52,6 @@ using namespace std; using namespace icu; using namespace folia; -using TiCC::operator<<; #define AlignReference LinkReference #define Alignment Relation @@ -104,7 +104,7 @@ void sanity_test004(){ startTestSerie(" first word " ); FoliaElement* w = 0; assertNoThrow( w = sanityDoc.words(0) ); - assertTrue( w->isinstance( Word_t ) ); + assertTrue( w->isinstance() ); assertTrue( w->id() == "WR-P-E-J-0000000001.head.1.s.1.w.1" ); assertTrue( w->text() == "Stemma" ); assertTrue( str(w) == "Stemma" ); @@ -126,7 +126,7 @@ void sanity_test006a( ){ startTestSerie(" second sentence " ); FoliaElement* s = 0; assertNoThrow( s = sanityDoc.sentences(1) ); - assertTrue( isinstance( s, Sentence_t ) ); + assertTrue( s->isinstance() ); assertEqual( s->id(), "WR-P-E-J-0000000001.p.1.s.1" ); assertTrue( !s->hastext() ); assertEqual( s->str() , "Stemma is een ander woord voor stamboom." ); @@ -136,7 +136,7 @@ void sanity_test006b(){ startTestSerie( " Sanity check - Sentence text (including retaining tokenisation) " ); // grab fifth sentence Sentence *s = sanityDoc.sentences(5); - assertTrue( isinstance( s, Sentence_t ) ); + assertTrue( s->isinstance() ); assertFalse( s->hastext() ); assertEqual( s->text(), "De andere handschriften krijgen ook een letter die verband kan houden met hun plaats van oorsprong óf plaats van bewaring." ); assertEqual( s->text(TEXT_FLAGS::RETAIN), "De andere handschriften krijgen ook een letter die verband kan houden met hun plaats van oorsprong óf plaats van bewaring ." ); @@ -162,7 +162,7 @@ void sanity_test007( ){ startTestSerie(" use index " ); FoliaElement *e = 0; assertNoThrow( e = sanityDoc["WR-P-E-J-0000000001.p.1.s.2.w.7"] ); - assertTrue( e->isinstance( Word_t ) ); + assertTrue( e->isinstance() ); assertEqual( e, sanityDoc.index("WR-P-E-J-0000000001.p.1.s.2.w.7") ); assertEqual( e->id(), string("WR-P-E-J-0000000001.p.1.s.2.w.7") ); assertEqual( e->text(), "stamboom" ); @@ -173,7 +173,7 @@ void sanity_test008a(){ startTestSerie(" division + head " ); FoliaElement *e = 0; assertNoThrow( e = sanityDoc["WR-P-E-J-0000000001.div0.1"] ); - assertTrue( e->isinstance( Division_t ) ); + assertTrue( e->isinstance() ); FoliaElement *h = 0; assertNoThrow( h = e->head() ); assertEqual( h, sanityDoc["WR-P-E-J-0000000001.head.1"] ); @@ -231,8 +231,12 @@ void sanity_test009( ){ FoliaElement *w = 0; assertNoThrow( w = sanityDoc.words(0) ); assertTrue( w->annotation() == w->select()[0] ); - assertTrue( w->annotation()->isinstance(PosAnnotation_t ) ); + assertTrue( w->annotation()->isinstance() ); +#if FOLIA_INT_VERSION < 221 assertTrue( isSubClass( PosAnnotation_t, AbstractTokenAnnotation_t ) ); +#else + assertTrue( is_subtype( ElementType::PosAnnotation_t, ElementType::AbstractTokenAnnotation_t ) ); +#endif #if FOLIA_INT_VERSION <= 215 || FOLIA_INT_VERSION >= 219 bool test = isSubClass(); assertTrue( test ); @@ -241,8 +245,11 @@ void sanity_test009( ){ assertTrue( w->pos() == "N(soort,ev,basis,onz,stan)" ); assertTrue( w->annotation()->sett() == "https://raw.githubusercontent.com/proycon/folia/master/setdefinitions/frog-mbpos-cgn" ); assertTrue( w->annotation()->annotator() == "frog" ); +#if FOLIA_INT_VERSION < 221 assertTrue( w->annotation()->annotatortype() == AUTO ); - +#else + assertTrue( w->annotation()->annotatortype() == AnnotatorType::AUTO ); +#endif } void sanity_test010( ){ @@ -252,13 +259,16 @@ void sanity_test010( ){ FoliaElement *l = 0; assertNoThrow( l = w->annotation() ); assertTrue( l == w->select()[0] ); - assertTrue( isinstance( l, LemmaAnnotation_t ) ); + assertTrue( l->isinstance() ); assertTrue( l->cls() == "stemma" ); assertTrue( w->lemma() == "stemma" ); assertTrue( l->sett() == "lemmas-nl" ); assertTrue( l->annotator() == "tadpole" ); +#if FOLIA_INT_VERSION < 221 assertTrue( l->annotatortype() == AUTO ); - +#else + assertTrue( l->annotatortype() == AnnotatorType::AUTO ); +#endif } void sanity_test011( ){ @@ -326,24 +336,24 @@ int check( FoliaElement *parent, const string& indent, ostream& os, int& fails ) for ( size_t i=0; i < parent->size(); ++i ){ FoliaElement *child = parent->index(i); os << indent << repr( child ) << endl; - if ( ! ( (parent->isinstance( SyntacticUnit_t ) - || parent->isinstance( Chunk_t ) - || parent->isinstance( Entity_t ) - || parent->isinstance( TimeSegment_t ) - || parent->isinstance( TimingLayer_t ) - || parent->isinstance( CoreferenceChain_t ) - || parent->isinstance( CoreferenceLink_t ) - || parent->isinstance( SemanticRole_t ) - || parent->isinstance( Headspan_t ) - || parent->isinstance( Source_t ) - || parent->isinstance( Target_t ) - || parent->isinstance( Relation_t ) - || parent->isinstance( Sentiment_t ) - || parent->isinstance( Statement_t ) - || parent->isinstance( Observation_t ) - || parent->isinstance( Dependency_t ) - || parent->isinstance( DependencyDependent_t ) ) - && ( child->isinstance( Word_t ) || child->isinstance( Morpheme_t )) ) ){ + if ( ! ( (parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() + || parent->isinstance() ) + && ( child->isinstance() || child->isinstance()) ) ){ ++count; if ( parent != child->parent() ){ // os << indent << "^ DAAR!" << endl; @@ -417,7 +427,7 @@ void sanity_test020a(){ FoliaElement *s = sanityDoc["WR-P-E-J-0000000001.p.1.s.1"]; FoliaElement *l = 0; assertNoThrow( l = s->annotation() ); - assertTrue( isinstance( l->index(0), SyntacticUnit_t ) ); + assertTrue( l->index(0)->isinstance() ); assertTrue( l->index(0)->cls() == "sentence" ); assertTrue( l->index(0)->index(0)->cls() == "subject" ); assertTrue( l->index(0)->index(0)->text() == "Stemma" ); @@ -427,7 +437,6 @@ void sanity_test020a(){ assertTrue( l->index(0)->index(2)->index(1)->cls() == "pp" ); assertTrue( l->index(0)->index(2)->index(1)->text() == "voor stamboom" ); assertEqual( l->index(0)->index(2)->text(), "een ander woord voor stamboom" ); - } void sanity_test020b(){ @@ -435,7 +444,7 @@ void sanity_test020b(){ FoliaElement *s = sanityDoc["WR-P-E-J-0000000001.p.1.s.1"]; ChunkingLayer *l = 0; assertNoThrow( l = s->annotation() ); - assertTrue( isinstance( l->index(0), Chunk_t ) ); + assertTrue( l->index(0)->isinstance() ); assertTrue( l->index(0)->text() == "een ander woord" ); assertTrue( l->index(1)->text() == "voor stamboom" ); @@ -446,7 +455,7 @@ void sanity_test020c(){ FoliaElement *s = sanityDoc["WR-P-E-J-0000000001.p.1.s.1"]; EntitiesLayer *l = 0; assertNoThrow( l = s->annotation() ); - assertTrue( isinstance( l->index(0), Entity_t ) ); + assertTrue( l->index(0)->isinstance() ); assertTrue( l->index(0)->text() == "ander woord" ); } @@ -490,7 +499,7 @@ void sanity_test020e(){ TimingLayer *l = 0; assertNoThrow( l = s->annotation() ); - assertTrue( isinstance( l->index(0), TimeSegment_t ) ); + assertTrue( l->index(0)->isinstance() ); assertEqual( l->index(0)->text(), "een ander woord" ) ; assertEqual( l->index(1)->cls(), "cough" ); assertEqual( l->index(2)->text(), "voor stamboom" ); @@ -530,7 +539,7 @@ void sanity_test021(){ startTestSerie(" Obtaining previous word " ); FoliaElement *w = sanityDoc["WR-P-E-J-0000000001.p.1.s.2.w.7"]; FoliaElement *prevw = w->previous(); - assertTrue( prevw->isinstance( Word_t ) ); + assertTrue( prevw->isinstance() ); assertTrue( prevw->text() == "zo'n" ); } @@ -539,7 +548,7 @@ void sanity_test022(){ startTestSerie(" Obtaining next word " ); FoliaElement *w = sanityDoc["WR-P-E-J-0000000001.p.1.s.2.w.7"]; FoliaElement *prevw = w->next(); - assertTrue( prevw->isinstance( Word_t ) ); + assertTrue( prevw->isinstance() ); assertTrue( prevw->text() == "," ); } @@ -572,7 +581,7 @@ void sanity_test023c(){ vector context = w->leftcontext(3,"?"); assertTrue( context.size() == 3 ); #if FOLIA_INT_VERSION <= 215 - assertTrue( context[0]->isinstance( Placeholder_t ) q); + assertTrue( context[0]->isinstance() q); #else assertTrue( context[0]->is_placeholder() ); #endif @@ -610,7 +619,7 @@ void sanity_test024c(){ assertTrue( context.size() == 3 ); assertTrue( text(context[0]) == "University" ); #if FOLIA_INT_VERSION <= 215 - assertTrue( context[1]->isinstance(PlaceHolder_t) ); + assertTrue( context[1]->isinstance() ); #else assertTrue( context[1]->is_placeholder() ); #endif @@ -653,7 +662,7 @@ void sanity_test025c(){ assertEqual( text(context[301]), "handschrift" ); assertTrue( text(context[202]) == "nil" ); #if FOLIA_INT_VERSION <= 215 - assertTrue( context[500]->isinstance(PlaceHolder_t) ); + assertTrue( context[500]->isinstance() ); #else assertTrue( context[500]->is_placeholder() ); #endif @@ -663,18 +672,28 @@ void sanity_test026a(){ startTestSerie(" Features " ); FoliaElement *w = sanityDoc["WR-P-E-J-0000000001.p.1.s.6.w.1"]; FoliaElement *pos = w->annotation(); -#if FOLIA_INT_VERSION <= 215 || FOLIA_INT_VERSION >= 219 +#if FOLIA_INT_VERSION <= 215 assertTrue( pos->isSubClass( AbstractTokenAnnotation_t ) ); #endif +#if FOLIA_INT_VERSION < 221 assertTrue( isSubClass( pos->element_id(), AbstractTokenAnnotation_t ) ); - assertTrue( pos->isinstance(PosAnnotation_t) ); +#else + assertTrue( pos->isSubClass() ); + assertTrue( is_subtype( pos->element_id(), ElementType::AbstractTokenAnnotation_t ) ); +#endif + assertTrue( pos->isinstance() ); assertTrue( pos->cls() == "WW(vd,prenom,zonder)" ); assertTrue( len(pos) == 1 ); vector features = pos->select(); assertTrue( len(features) == 1 ); +#if FOLIA_INT_VERSION < 221 assertFalse( isSubClass( features[0]->element_id(), Sentence_t ) ); assertTrue( isSubClass( features[0]->element_id(), Feature_t ) ); - assertTrue( isinstance(features[0], Feature_t ) ); +#else + assertFalse( is_subtype( features[0]->element_id(), ElementType::Sentence_t ) ); + assertTrue( is_subtype( features[0]->element_id(), ElementType::Feature_t ) ); +#endif + assertTrue( features[0]->isinstance() ); assertTrue( features[0]->subset() == "head" ); assertTrue( features[0]->cls() == "WW" ); KWargs args; @@ -690,7 +709,7 @@ void sanity_test026b(){ startTestSerie(" Metric " ); FoliaElement *p= sanityDoc.paragraphs(0); FoliaElement *m = p->annotation(); - assertTrue( isinstance(m, Metric_t ) ); + assertTrue( m->isinstance() ); assertEqual( m->cls(), "sentenceCount" ); assertEqual( m->feat("value"), "8" ); } @@ -709,15 +728,15 @@ void sanity_test028() { FoliaElement *w = sanityDoc["WR-P-E-J-0000000001.p.1.s.8.w.15"]; FoliaElement *s = w->sentence(); - assertTrue( s->isinstance( Sentence_t ) ); + assertTrue( s->isinstance() ); assertTrue( s->id() == "WR-P-E-J-0000000001.p.1.s.8" ); FoliaElement *p = w->paragraph(); - assertTrue( isinstance( p, Paragraph_t ) ); + assertTrue( p->isinstance() ); assertTrue( p->id() == "WR-P-E-J-0000000001.p.1" ); FoliaElement *div = w->division(); - assertTrue( isinstance( div, Division_t ) ); + assertTrue( div->isinstance() ); assertTrue( div->id() == "WR-P-E-J-0000000001.div0.1" ); assertTrue( w->incorrection() == 0 ); @@ -726,7 +745,7 @@ void sanity_test028() { void sanity_test029(){ startTestSerie(" Sanity Check - Quote " ); FoliaElement *q = sanityDoc["WR-P-E-J-0000000001.p.1.s.8.q.1"]; - assertTrue( q->isinstance( Quote_t ) ); + assertTrue( q->isinstance() ); assertTrue( q->text() == "volle lijn" ); FoliaElement *s = sanityDoc["WR-P-E-J-0000000001.p.1.s.8"]; @@ -759,7 +778,6 @@ void sanity_test030( ){ FoliaElement *w2= sanityDoc["WR-P-E-J-0000000001.p.1.s.6.w.31"]; assertTrue( w2->text() == "vierkante" ); assertTrue( w2->stricttext() == "vierkante" ); - } void sanity_test030b( ){ @@ -769,7 +787,7 @@ void sanity_test030b( ){ assertTrue( len(t) == 3 ); assertEqual( t->text(), "De \nFoLiA developers zijn:" ); assertEqual( t->index(0)->text(), "De "); - assertTrue( isinstance( t->index(1), TextMarkupString_t ) ); + assertTrue( t->index(1)->isinstance() ); assertEqual( t->index(1)->text(), "\nFoLiA developers" ); assertEqual( t->index(2)->text(), " zijn:" ); } @@ -1035,11 +1053,11 @@ void sanity_test041c(){ void sanity_test042(){ startTestSerie( " Sanity check - Table " ); FoliaElement *table = sanityDoc["example.table.1"]; - assertTrue( isinstance( table, Table_t) ); - assertTrue( isinstance( table->index(0), TableHead_t) ); - assertTrue( isinstance( table->index(0)->index(0), Row_t) ); + assertTrue( table->isinstance() ); + assertTrue( table->index(0)->isinstance() ); + assertTrue( table->index(0)->index(0)->isinstance() ); assertEqual( len( table->index(0)->index(0)), size_t(2) ); // two cells - assertTrue( isinstance(table->index(0)->index(0)->index(0), Cell_t) ); + assertTrue( table->index(0)->index(0)->index(0)->isinstance() ); assertEqual( table->index(0)->index(0)->index(0)->text(), "Naam" ); assertEqual( table->index(0)->index(0)->text(), "Naam | Universiteit" ); //text of whole row } @@ -1071,7 +1089,7 @@ void sanity_test044a(){ FoliaElement *r2 = sanityDoc["sandbox.3.str"]; assertEqual( r1, r2 ); // testing resolving references t = sanityDoc["WR-P-E-J-0000000001.p.1.s.6"]->text_content(); - assertTrue( t->index(t->size()-1)->isinstance( Linebreak_t) ); // did we get the linebreak properly? + assertTrue( t->index(t->size()-1)->isinstance() ); // did we get the linebreak properly? // testing nesting assertEqual( len(st), size_t(2) ); assertEqual( st->index(0), sanityDoc["sandbox.3.str.bold"] ); @@ -1625,13 +1643,20 @@ void sanity_test102k(){ Document doc; assertNoThrow( doc.read_from_string(xml) ); FoliaElement *text = doc["example.text.1"]; +#if FOLIA_INT_VERSION < 221 assertEqual( doc.default_annotatortype(AnnotationType::GAP), AUTO ); +#else + assertEqual( doc.default_annotatortype(AnnotationType::GAP), + AnnotatorType::AUTO ); +#endif vector v = text->select(); assertEqual( v[0]->xmlstring(), "" ); assertNoThrow( doc.declare( AnnotationType::GAP, "gap-set", "annotatortype='manual'" ) ); -#if FOLIA_INT_VERSION >= 211 +#if FOLIA_INT_VERSION >= 221 + assertEqual( doc.default_annotatortype(AnnotationType::GAP), AnnotatorType::MANUAL ); +#elif FOLIA_INT_VERSION >= 211 assertEqual( doc.default_annotatortype(AnnotationType::GAP), MANUAL ); #else assertEqual( doc.default_annotatortype(AnnotationType::GAP), UNDEFINED ); @@ -1835,7 +1860,7 @@ void sanity_test104a( ){ assertNoThrow( doc.read_from_string(xml) ); // assertNoThrow( doc.save( "/tmp/test104a.xml" ) ); // assertTrue( isinstance(doc.doc(0), Speech_t) ); - assertTrue( isinstance(doc["example.speech.utt.1"], Utterance_t) ); + assertTrue( doc["example.speech.utt.1"]->isinstance() ); assertEqual( doc["example.speech.utt.1"]->phon(), "həlˈəʊ wˈɜːld" ); assertThrow( doc["example.speech.utt.1"]->text(), NoSuchText ); // doesn't exist assertEqual( doc["example.speech.utt.2"]->phon(), "həlˈəʊ wˈɜːld" ); @@ -1871,7 +1896,7 @@ void sanity_test104b( ){ assertNoThrow( doc.read_from_string(xml) ); assertNoThrow( doc.save( "/tmp/test104b.xml" ) ); //assertTrue( isinstance(doc.doc(), folia.Speech) ); - assertTrue( isinstance(doc["example.speech.utt.1"], Utterance_t) ); + assertTrue( doc["example.speech.utt.1"]->isinstance() ); assertEqual( doc["example.speech.utt.1"]->phon(), "həlˈəʊ wˈɜːld" ); assertThrow( doc["example.speech.utt.1"]->text(), NoSuchText ); // doesn't exist assertEqual( doc["example.speech.utt.2"]->phon(), "həlˈəʊ wˈɜːld" ); @@ -2074,12 +2099,16 @@ void sanity_test109( ){ assertTrue( ( isSubClass() ) ); assertTrue( ( isSubClass() ) ); assertFalse( ( isSubClass() ) ); - assertFalse( ( isSubClass() ) ); - assertFalse( ( isSubClass() ) ); assertTrue( ( isSubClass() ) ); assertTrue( ( isSubClass() ) ); #endif +#if FOLIA_INT_VERSION < 221 assertTrue( isSubClass( PosAnnotation_t, AbstractTokenAnnotation_t ) ); +#else + assertTrue( is_subtype( ElementType::PosAnnotation_t, ElementType::AbstractTokenAnnotation_t ) ); + assertTrue( ( isSubClass() ) ); + assertTrue( ( isSubClass() ) ); +#endif } void sanity_test110(){ @@ -2227,7 +2256,11 @@ void sanity_test130( ){ root=root->index(0); // Text vector dv = root->select(); assertEqual( dv.size(), 5 ); +#if FOLIA_INT_VERSION < 221 dv = root->select(false); +#else + dv = root->select(SELECT_FLAGS::LOCAL); +#endif assertEqual( dv.size(), 2 ); dv = root->select("role"); assertEqual( dv.size(), 3 ); diff --git a/tests/foliadiff.sh b/tests/foliadiff.sh index a2fc2d7..373d1b1 100755 --- a/tests/foliadiff.sh +++ b/tests/foliadiff.sh @@ -1,12 +1,35 @@ # /bin/sh -x -if [ -z "$exe" ] +if [ "$exe" = "" ] then - if which folialint >/dev/null 2>/dev/null; then - exe=$(which folialint) + if which folialint >/dev/null 2>/dev/null + then + exe=$(which folialint) fi fi -if [ -z "$exe" ]; then +if [ "$exe" = "" ] +then + exe="$HOME/usr/local/bin/folialint" + if [ ! -f $exe ] + then + exe="/exp/sloot/usr/local/bin/folialint" + if [ ! -f $exe ] + then + exe="/usr/local/bin/folialint" + if [ ! -f $exe ] + then + exe="/usr/bin/folialint" + if [ ! -f $exe ] + then + exe="" + fi + fi + fi + fi +fi + +if [ "$exe" = "" ]; +then "cannot locate folialint" exit 1 fi @@ -17,10 +40,21 @@ if [ $# -ne 2 ] exit 1 fi +run_lint(){ + $exe --strip --canonical "$1" --output $2 + if [ $? -ne 0 ] + then + echo "foliadiff.sh: $1 is INVALID FoLiA" + exit 1 + fi +} + t1=/tmp/${1##*/}.s1 t2=/tmp/${2##*/}.s2 -$exe --strip --KANON "$1" --output $t1 -$exe --strip --KANON "$2" --output $t2 + +run_lint $1 $t1 & +run_lint $2 $t2 & +wait diff $t1 $t2 if [ $? -ne 0 ] then