Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,37 @@ jobs:
fi
echo "[compiled-bridge] interpreter-only builtins work in a compiled analyzer"

- name: Compiled analyzer runs zone mode
shell: bash
run: |
set -eo pipefail
# A compiled analyzer used to ignore zone and endzone lines and run
# every pass on the whole document. run_analyzer() now hands the
# zone passes to Arun::zones. Build the zone-mode fixture compiled
# and compare it with the interpreted run, -DEV trees included.
FIX=.github/workflows/tests/zone-mode
LIBS="$(cygpath -m "$GITHUB_WORKSPACE")/compile-libs"
rm -rf "$FIX/logs" "$FIX"/input/*_log "$FIX/output" "$FIX/run" "$FIX/build"
mkdir -p "$FIX/logs"
./bin/Release/nlp.exe -ANA "$FIX" -WORK ./ -DEV "$FIX/input/text.txt" | tr -d '\r' | grep -E '^(zone|summary)' > zone-interpreted.txt
(cd "$FIX/input/text.txt_log" && ls *.tree) > zone-trees.txt
rm -rf "$FIX/input/text.txt_log"
cp .github/workflows/tests/compiled-bridge/CMakeLists.txt .github/workflows/tests/compiled-bridge/StdAfx.h "$FIX/"
./bin/Release/nlp.exe -COMPILEANA -ANA "$FIX" -WORK ./ "$FIX/input/text.txt"
grep -q "Arun::zones" "$FIX/run/analyzer.cpp"
cmake -S "$FIX" -B "$FIX/build" -A x64 -DENGINE_LIBS="$LIBS"
cmake --build "$FIX/build" --config Release
rm -rf "$FIX/input/text.txt_log" "$FIX/output"
./bin/Release/nlp.exe -COMPILED -ANA "$FIX" -WORK ./ -DEV "$FIX/input/text.txt" | tr -d '\r' | grep -E '^(zone|summary)' > zone-compiled.txt
if ! diff zone-interpreted.txt zone-compiled.txt; then
echo "FAIL(compiled zone mode): compiled output differs from interpreted"; exit 1
fi
if ! diff zone-trees.txt <(cd "$FIX/input/text.txt_log" && ls *.tree); then
echo "FAIL(compiled zone mode): compiled -DEV trees differ from interpreted"; exit 1
fi
rm -f "$FIX/CMakeLists.txt" "$FIX/StdAfx.h" zone-interpreted.txt zone-compiled.txt zone-trees.txt
echo "[compiled zone mode] a compiled analyzer runs the zone passes once per zone"

- name: Upload nlpengine-compile-libs.zip
uses: actions/upload-artifact@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ runs once per node of that type:
`_TEXTZONE` nodes into sections); that stops the run with an error.
- With `-DEV`, the first three zones write their pass trees as
`z001-ana040.tree` and so on.
- A compiled analyzer ignores the `zone` and `endzone` lines and runs every
pass on the whole document.
- Compiled analyzers run zones the same way (since 4.2.49; before that they
ignored the `zone` and `endzone` lines).

On *Pride and Prejudice* (738 KB) with parse-en-us zoned by `_TEXTZONE`, peak
memory went from 473 MB to 153 MB and time from 275 to 283 seconds;
Expand Down
2 changes: 2 additions & 0 deletions include/Api/lite/Arun.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class LITE_API Arun
static bool python(Parse *, int, const _TCHAR *); // 07/14/26. compiled python pass.
static bool lines(Parse *, int);
static void runPostcode(Parse *parse, const PASS *pass); // #392.
static bool zones(Parse *parse, const _TCHAR *ztype, // Zone mode.
bool (*zonefn)(Parse *), bool (*endfn)(Parse *));
static bool patExecute(
Parse *,
const PASS *,
Expand Down
16 changes: 12 additions & 4 deletions include/Api/lite/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All rights reserved.
#include <time.h>
#include <set>
#include <chrono>
#include <functional>

typedef void TREE; // 07/07/03 AM.
typedef void LTREE; // 07/07/03 AM.
Expand Down Expand Up @@ -231,6 +232,14 @@ class LITE_API Parse
int runPass(Delt<Seqn> *seq, long &num);
// Zone mode: the passes after a "zone _type" line run once per _type node.
int executeZones(Delt<Seqn> *first, _TCHAR *ztype);
// The same for a compiled analyzer: zonefn runs the zone passes, endfn
// the passes after endzone (or 0). Called by Arun::zones.
bool runZones(const _TCHAR *ztype, bool (*zonefn)(Parse *),
bool (*endfn)(Parse *));
int zoneLoop(const _TCHAR *ztype, const std::function<int()> &zone,
const std::function<int()> &wrap, const std::function<int()> &whole);
// Dump-file prefix for a pass in zone mode; may turn dumps off.
_TCHAR *zonePrefix(_TCHAR *prefix, bool &flogfiles, bool &ftimepass);
long getZoneNum() {return zoneNum_;}
bool getZoneFirst() {return zoneFirst_;}
bool getZoneLast() {return zoneLast_;}
Expand Down Expand Up @@ -533,10 +542,7 @@ class LITE_API Parse
bool ftimepass,
clock_t &s_time
);
#ifndef LINUX
inline
#endif
void iniPass( // 05/20/00 AM.
void iniPass( // Not inline: Arun.cpp calls it too. // 05/20/00 AM.
int num, // Current pass number.
_TCHAR *prefix, // Prefix for naming dump files.
bool flogfiles,
Expand Down Expand Up @@ -688,6 +694,8 @@ class LITE_API Parse
unsigned long runTicks_ = 0; // Calls since the clock was last read.
bool runStopped_ = false;

_TCHAR zprefix_[32] = {0}; // zonePrefix()'s "z001-ana".

#ifndef STABLE_
public:
static int getCount();
Expand Down
21 changes: 21 additions & 0 deletions lite/Arun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ _TCHAR *prefix = _T("ana"); // Prefix for naming files.
bool flogfiles = parse->eana_->getFlogfiles();
bool ftimepass = parse->eana_->getFtimepass();

prefix = parse->zonePrefix(prefix, flogfiles, ftimepass); // Zone mode.
parse->iniPass(num,prefix,flogfiles,ftimepass,true,0,salgo, // 05/21/00 AM.
/*DU*/fout,sout,s_time,pretname);

Expand Down Expand Up @@ -153,6 +154,7 @@ _TCHAR *prefix = _T("ana"); // Prefix for naming files.
bool flogfiles = parse->eana_->getFlogfiles();
bool ftimepass = parse->eana_->getFtimepass();

prefix = parse->zonePrefix(prefix, flogfiles, ftimepass); // Zone mode.
parse->iniPass(num,prefix,flogfiles,ftimepass,true,0,salgo,
/*DU*/fout,sout,s_time,pretname);

Expand Down Expand Up @@ -188,6 +190,7 @@ _TCHAR *prefix = _T("ana"); // Prefix for naming files.
bool flogfiles = parse->eana_->getFlogfiles();
bool ftimepass = parse->eana_->getFtimepass();

prefix = parse->zonePrefix(prefix, flogfiles, ftimepass); // Zone mode.
parse->iniPass(num,prefix,flogfiles,ftimepass,true,0,salgo,
/*DU*/fout,sout,s_time,pretname);

Expand Down Expand Up @@ -224,6 +227,7 @@ _TCHAR *prefix = _T("ana"); // Prefix for naming files.
bool flogfiles = parse->eana_->getFlogfiles();
bool ftimepass = parse->eana_->getFtimepass();

prefix = parse->zonePrefix(prefix, flogfiles, ftimepass); // Zone mode.
parse->iniPass(num,prefix,flogfiles,ftimepass,true,0,salgo,
/*DU*/fout,sout,s_time,pretname);

Expand Down Expand Up @@ -261,6 +265,7 @@ _TCHAR *prefix = _T("ana"); // Prefix for naming files.
bool flogfiles = parse->eana_->getFlogfiles();
bool ftimepass = parse->eana_->getFtimepass();

prefix = parse->zonePrefix(prefix, flogfiles, ftimepass); // Zone mode.
parse->iniPass(num,prefix,flogfiles,ftimepass,true,0,salgo,
/*DU*/fout,sout,s_time,pretname);

Expand Down Expand Up @@ -294,6 +299,7 @@ _TCHAR *prefix = _T("ana"); // Prefix for naming files.
bool flogfiles = parse->eana_->getFlogfiles();
bool ftimepass = parse->eana_->getFtimepass();

prefix = parse->zonePrefix(prefix, flogfiles, ftimepass); // Zone mode.
parse->iniPass(num,prefix,flogfiles,ftimepass,true,0,salgo, // 05/21/00 AM.
/*DU*/fout,sout,s_time,pretname);

Expand All @@ -306,6 +312,19 @@ return true;
}


/********************************************
* FN: ZONES
* SUBJ: Zone mode in a compiled analyzer.
* NOTE: run_analyzer() ends with this after a zone line; see Seqn::gen.
********************************************/

bool Arun::zones(Parse *parse, const _TCHAR *ztype,
bool (*zonefn)(Parse *), bool (*endfn)(Parse *))
{
return parse->runZones(ztype, zonefn, endfn);
}


/********************************************
* FN: RUNPOSTCODE
* SUBJ: Run a compiled pass's @POSTCODE region, after its rules (#392).
Expand Down Expand Up @@ -355,6 +374,7 @@ _TCHAR *prefix = _T("ana"); // Prefix for naming files.
bool flogfiles = parse->eana_->getFlogfiles();
bool ftimepass = parse->eana_->getFtimepass();

prefix = parse->zonePrefix(prefix, flogfiles, ftimepass); // Zone mode.
parse->iniPass(num,prefix,flogfiles,ftimepass,true,sfile,salgo, // 05/20/00 AM.
/*DU*/fout,sout,s_time,pretname);

Expand Down Expand Up @@ -415,6 +435,7 @@ _TCHAR *prefix = _T("ana"); // Prefix for naming files.
bool flogfiles = parse->eana_->getFlogfiles();
bool ftimepass = parse->eana_->getFtimepass();

prefix = parse->zonePrefix(prefix, flogfiles, ftimepass); // Zone mode.
parse->iniPass(num,prefix,flogfiles,ftimepass,true,sfile,salgo, // 05/20/00 AM.
/*DU*/fout,sout,s_time,pretname);

Expand Down
4 changes: 2 additions & 2 deletions lite/Aseq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ Ifile *rf; // 12/20/01 AM.
for (selt = (Delt<Seqn> *)Aseq::firstPass(nlp); selt; selt = selt->Right())
{
seqn = selt->getData();
seqn->setPassnum(++currseqpass); // In case... // 05/20/01 AM.
seqn->setPassnum(seqn->isZoneMarker() ? 0 : ++currseqpass); // 05/20/01 AM.
if (seqn->getActive()) // Pass that will be executed.
{
if (!(seqn->getAlgo()) // 12/20/01 AM.
Expand Down Expand Up @@ -865,7 +865,7 @@ int num = 0; // Current pass number.

num = 0;
for (seq = Aseq::firstPass(nlp); seq; seq = Aseq::nextPass(seq))
Aseq::setPassnum(seq, ++num);
Aseq::setPassnum(seq, ((Delt<Seqn> *) seq)->getData()->isZoneMarker() ? 0 : ++num);
}


Expand Down
5 changes: 1 addition & 4 deletions lite/ana.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Ifile *rf = 0; // 12/20/01 AM.
for (selt = slist->getFirst(); selt; selt = selt->Right())
{
seqn = selt->getData();
seqn->setPassnum(++currseqpass); // 05/10/00 AM.
seqn->setPassnum(seqn->isZoneMarker() ? 0 : ++currseqpass); // 05/10/00 AM.
if (seqn->getActive())
{
if (!internPass(seqn, rfa, erfa)) // Asynchrony. // 12/11/99 AM.
Expand Down Expand Up @@ -599,9 +599,6 @@ else if ( !strcmp_i(s_algo, _T("zone"))) // "zone _type": the passes below
errOut(&gerrStr,false);
return false;
}
if (gen)
std::_t_cerr << _T("[Warning: a compiled analyzer ignores the zone line; ")
<< _T("its later passes run on the whole document.]") << std::endl;
return true;
}
else if ( !strcmp_i(s_algo, _T("endzone"))) // The passes below run once,
Expand Down
Loading
Loading