Hello community, here is the log from the commit of package foma for openSUSE:Factory checked in at 2020-03-04 09:38:41 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/foma (Old) and /work/SRC/openSUSE:Factory/.foma.new.26092 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "foma" Wed Mar 4 09:38:41 2020 rev:3 rq:780929 version:0.9.18+git20200221.5e5521e Changes: -------- --- /work/SRC/openSUSE:Factory/foma/foma.changes 2018-10-02 19:40:43.230272107 +0200 +++ /work/SRC/openSUSE:Factory/.foma.new.26092/foma.changes 2020-03-04 09:38:48.673870451 +0100 @@ -1,0 +2,20 @@ +Mon Mar 02 12:07:36 UTC 2020 - [email protected] + +- Update to version 0.9.18+git20200221.5e5521e bsc#1160265: + * Ignore dylibs + * Removed dependency on six + * Bugfixes for Python + * Added Python 3 port of foma2js.perl + * Better py3 compatibility + * Add test for apply_down(). + * Get apply_up() working. + * Add simple Python tests. + * Port FST.encode() to use correct types for Python 3. + * Add Python six 1.11.0 module. + * Added TextWrangler codeless language modules. + * add object files and many temp files to .gitignore + * remove SVN_REV var in Makefile +- Remove upstream merged patch: + * foma-fix-sizeof.patch + +------------------------------------------------------------------- Old: ---- foma-0.9.18+git20180511.bad2f09.tar.xz foma-fix-sizeof.patch New: ---- foma-0.9.18+git20200221.5e5521e.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ foma.spec ++++++ --- /var/tmp/diff_new_pack.HNKfP1/_old 2020-03-04 09:38:49.105870710 +0100 +++ /var/tmp/diff_new_pack.HNKfP1/_new 2020-03-04 09:38:49.109870712 +0100 @@ -1,7 +1,7 @@ # # spec file for package foma # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,16 +18,14 @@ %define libname libfoma0 Name: foma -Version: 0.9.18+git20180511.bad2f09 +Version: 0.9.18+git20200221.5e5521e Release: 0 Summary: Finite-state compiler and C library License: Apache-2.0 -Group: Productivity/Text/Utilities URL: https://fomafst.github.io/ # Source must be from git tarball has different license than git, no idea why Source0: foma-%{version}.tar.xz Patch0: foma-harden-build.patch -Patch1: foma-fix-sizeof.patch BuildRequires: bison BuildRequires: flex BuildRequires: ncurses-devel @@ -44,7 +42,6 @@ %package -n %{libname} Summary: Finite-state C library -Group: System/Libraries %description -n %{libname} The library contains efficient implementations of all classical @@ -56,7 +53,6 @@ %package devel Summary: Finite-state C library development files and headers -Group: Development/Libraries/C and C++ Requires: %{libname} = %{version} %description devel @@ -65,14 +61,13 @@ %prep %setup -q -n %{name}-%{version}/%{name} %patch0 -p2 -%patch1 -p2 -sed -i '/^CFLAGS/c\CFLAGS = %{optflags} -Wl,--as-needed -D_GNU_SOURCE -std=c99 -fvisibility=hidden -fPIC' Makefile +sed -i '/^CFLAGS/c\CFLAGS = %{optflags} -fcommon -Wl,--as-needed -D_GNU_SOURCE -std=c99 -fvisibility=hidden -fPIC' Makefile sed -i '/^LDFLAGS/c\LDFLAGS = -lreadline -lz -lreadline -fpic' Makefile sed -i '/^FLOOKUPLDFLAGS/c\FLOOKUPLDFLAGS = libfoma.a -lz -fpic' Makefile %build # hand written Makefile that gets to be quite PITA -make -j1 +%make_build -j1 %install %make_install \ ++++++ foma-0.9.18+git20180511.bad2f09.tar.xz -> foma-0.9.18+git20200221.5e5521e.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/Makefile new/foma-0.9.18+git20200221.5e5521e/foma/Makefile --- old/foma-0.9.18+git20180511.bad2f09/foma/Makefile 2018-05-11 19:04:08.000000000 +0200 +++ new/foma-0.9.18+git20200221.5e5521e/foma/Makefile 2020-02-21 22:45:41.000000000 +0100 @@ -5,7 +5,6 @@ includedir = $(prefix)/include VERSION = 0.9.18 -SVN_REV = $(shell svn info | grep "Last Changed Rev" | cut -f4 -d\ ) CC = gcc RANLIB = ranlib YACC = bison -v @@ -16,7 +15,7 @@ RM = /bin/rm -f LDFLAGS = -lreadline -lz -ltermcap FLOOKUPLDFLAGS = libfoma.a -lz -CFLAGS = -O3 -Wall -D_GNU_SOURCE -std=c99 -fvisibility=hidden -fPIC -DSVN_REV=$(SVN_REV) +CFLAGS = -O3 -Wall -D_GNU_SOURCE -std=c99 -fvisibility=hidden -fPIC FOMAOBJS = foma.o stack.o iface.o lex.interface.o LIBOBJS = int_stack.o define.o determinize.o apply.o rewrite.o lexcread.o topsort.o flags.o minimize.o reverse.o extract.o sigma.o io.o structures.o constructions.o coaccessible.o utf8.o spelling.o dynarray.o mem.o stringhash.o trie.o lex.lexc.o lex.yy.o lex.cmatrix.o regex.o diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/contrib/foma.plist new/foma-0.9.18+git20200221.5e5521e/foma/contrib/foma.plist --- old/foma-0.9.18+git20180511.bad2f09/foma/contrib/foma.plist 1970-01-01 01:00:00.000000000 +0100 +++ new/foma-0.9.18+git20200221.5e5521e/foma/contrib/foma.plist 2020-02-21 22:45:41.000000000 +0100 @@ -0,0 +1,205 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" + "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + +<!-- Textwrangler codeless language module for .foma files + + Copyright (c) 2017 Lane Schwartz + This file is may be redistributed under the same license as Foma. + + For TextWrangler, copy this file to: + ~/Library/Application Support/TextWrangler/Language Modules/ + and then restart TextWrangler. +--> + +<dict> + <!-- You must identify the plist as a CLM: --> + <key>BBEditDocumentType</key> + <string>CodelessLanguageModule</string> + + <!-- You must identify your language: --> + <key>BBLMLanguageDisplayName</key> + <string>Foma</string> + + <key>BBLMLanguageCode</key> + <string>foma</string> + + <key>BBLMPreferredFilenameExtension</key> + <string>foma</string> + + <key>BBLMSuffixMap</key> + <array> + <dict> + <key>BBLMLanguageSuffix</key> + <string>.foma</string> + </dict> + </array> + + <!-- Specify a comment-out string: --> + <key>BBLMCommentLineDefault</key> + <string>!</string> + + <!-- Not required, but there’s not much point to + a language module if it doesn’t color syntax: --> + <key>BBLMColorsSyntax</key> + <true/> + + <key>BBLMSupportsTextCompletion</key> + <true/> + + + <!-- Specify some keywords. This isn’t required, either, + but it provides something to color: --> + <key>BBLMKeywordList</key> + <array> + <string>OFF</string> + <string>ON</string> + <string>ambiguous</string> + <string>apply</string> + <string>apropos</string> + <string>att</string> + <string>att-epsilon</string> + <string>clear</string> + <string>close</string> + <string>cmatrix</string> + <string>compact</string> + <string>complete</string> + <string>compose</string> + <string>compose-tristate</string> + <string>concatenate</string> + <string>crossproduct</string> + <string>def</string> + <string>define</string> + <string>defined</string> + <string>determinize</string> + <string>dot</string> + <string>down</string> + <string>echo</string> + <string>eliminate</string> + <string>equivalent</string> + <string>export</string> + <string>extract</string> + <string>flag</string> + <string>flag-diacritics</string> + <string>flags</string> + <string>for</string> + <string>functional</string> + <string>help</string> + <string>hopcroft-min</string> + <string>identity</string> + <string>ignore</string> + <string>in</string> + <string>intersect</string> + <string>invert</string> + <string>label</string> + <string>letter</string> + <string>lexc</string> + <string>lexc-align</string> + <string>license</string> + <string>load</string> + <string>lower-side</string> + <string>lower-universal</string> + <string>lower-words</string> + <string>machine</string> + <string>med</string> + <string>med-cutoff</string> + <string>med-limit</string> + <string>minimal</string> + <string>minimize</string> + <string>name</string> + <string>negate</string> + <string>net</string> + <string>non-null</string> + <string>null</string> + <string>obey-flags</string> + <string>one-plus</string> + <string>out</string> + <string>pairs</string> + <string>pop</string> + <string>print</string> + <string>print-pairs</string> + <string>print-sigma</string> + <string>print-space</string> + <string>prolog</string> + <string>prune</string> + <string>push</string> + <string>quit</string> + <string>quit-on-fail</string> + <string>random-lower</string> + <string>random-pairs</string> + <string>random-upper</string> + <string>random-words</string> + <string>read</string> + <string>recursive-define</string> + <string>re</string> + <string>regex</string> + <string>reverse</string> + <string>rotate</string> + <string>save</string> + <string>sequential</string> + <string>set</string> + <string>shortest-string</string> + <string>shortest-string-size</string> + <string>show</string> + <string>show-flags</string> + <string>shuffle</string> + <string>sigma</string> + <string>size</string> + <string>sort</string> + <string>source</string> + <string>spaced-text</string> + <string>stack</string> + <string>star-free</string> + <string>substitute</string> + <string>symbol</string> + <string>system</string> + <string>test</string> + <string>text</string> + <string>turn</string> + <string>twosided</string> + <string>unambiguous</string> + <string>undefine</string> + <string>union</string> + <string>up</string> + <string>upper</string> + <string>upper-side</string> + <string>upper-universal</string> + <string>upper-words</string> + <string>variable</string> + <string>variables</string> + <string>verbose</string> + <string>view</string> + <string>warranty</string> + <string>words</string> + <string>write</string> + <string>zero-plus</string> + <string>.#.</string> + + </array> + + + <!-- You must specify the character set for + keywords and identifiers. Substitute your own: --> + <key>Language Features</key> + <dict> + <key>Identifier and Keyword Character Class</key> + <string>A-Za-z0-9_\?!.</string> + + <key>Comment Pattern</key> + <string>(^#|[^.]#|#[^.]|!).+$</string> + + <key>String Pattern</key> + <string><![CDATA[ + (?x: + (?> " ( + [^"\r\\] (?# match anything potential ending quote, new line, or start of escape sequence) + | \\. (?# match any escape sequence pair) + )*? + " + ) + ) + ]]></string> + </dict> +</dict> +</plist> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/contrib/lexc.plist new/foma-0.9.18+git20200221.5e5521e/foma/contrib/lexc.plist --- old/foma-0.9.18+git20180511.bad2f09/foma/contrib/lexc.plist 1970-01-01 01:00:00.000000000 +0100 +++ new/foma-0.9.18+git20200221.5e5521e/foma/contrib/lexc.plist 2020-02-21 22:45:41.000000000 +0100 @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" + "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + +<!-- Textwrangler codeless language module for .lexc files + + Copyright (c) 2017 Lane Schwartz + This file is may be redistributed under the same license as Foma. + + For TextWrangler, copy this file to: + ~/Library/Application Support/TextWrangler/Language Modules/ + and then restart TextWrangler. +--> + +<dict> + <!-- You must identify the plist as a CLM: --> + <key>BBEditDocumentType</key> + <string>CodelessLanguageModule</string> + + <!-- You must identify your language: --> + <key>BBLMLanguageDisplayName</key> + <string>Lexc</string> + + <key>BBLMLanguageCode</key> + <string>lexc</string> + + <key>BBLMPreferredFilenameExtension</key> + <string>lexc</string> + + <key>BBLMSuffixMap</key> + <array> + <dict> + <key>BBLMLanguageSuffix</key> + <string>.lexc</string> + </dict> + </array> + + <!-- Specify a comment-out string: --> + <key>BBLMCommentLineDefault</key> + <string>!</string> + + <!-- Not required, but there’s not much point to + a language module if it doesn’t color syntax: --> + <key>BBLMColorsSyntax</key> + <true/> + + <key>BBLMSupportsTextCompletion</key> + <true/> + + + <!-- Specify some keywords. This isn’t required, either, + but it provides something to color: --> + <key>BBLMKeywordList</key> + <array> + <string>Multichar_Symbols</string> + <string>Definitions</string> + <string>LEXICON</string> + </array> + + <!-- You must specify the character set for + keywords and identifiers. Substitute your own: --> + <key>Language Features</key> + <dict> + <key>Identifier and Keyword Character Class</key> + <string>A-Za-z0-9_\?!.</string> + + <key>Comment Pattern</key> + <string>(!).+$</string> + + <key>String Pattern</key> + <string><![CDATA[ + (?x: + (?> " ( + [^"\r\\] (?# match anything potential ending quote, new line, or start of escape sequence) + | \\. (?# match any escape sequence pair) + )*? + " + ) + ) + ]]></string> + </dict> +</dict> +</plist> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/python/README.md new/foma-0.9.18+git20200221.5e5521e/foma/python/README.md --- old/foma-0.9.18+git20180511.bad2f09/foma/python/README.md 2018-05-11 19:04:08.000000000 +0200 +++ new/foma-0.9.18+git20200221.5e5521e/foma/python/README.md 2020-02-21 22:45:41.000000000 +0100 @@ -33,3 +33,7 @@ ``` cad[ARule|Rule one]cbd[BRule|Rule two]ccd ``` + +## foma2js.py + +This is a port of `foma/contrib/foma2js.perl` to Python 3. Get the help using `foma2js.py -h`. Everything else like in the original program. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/python/foma.py new/foma-0.9.18+git20200221.5e5521e/foma/python/foma.py --- old/foma-0.9.18+git20180511.bad2f09/foma/python/foma.py 2018-05-11 19:04:08.000000000 +0200 +++ new/foma-0.9.18+git20200221.5e5521e/foma/python/foma.py 2020-02-21 22:45:41.000000000 +0100 @@ -17,17 +17,37 @@ # See the License for the specific language governing permissions and # # limitations under the License. # -from sys import maxsize +from sys import maxsize, version_info from ctypes import * from ctypes.util import find_library fomalibpath = find_library('foma') foma = cdll.LoadLibrary(fomalibpath) + class FSTstruct(Structure): + _fields_ = [ + ("name", c_char * 40), + ("arity", c_int), + ("arccount", c_int), + ("statecount", c_int), + ("linecount", c_int), + ("finalcount", c_int), + ("pathcount", c_longlong), + ("is_deterministic", c_int), + ("is_pruned", c_int), + ("is_minimized", c_int), + ("is_epsilon_free", c_int), + ("is_loop_free", c_int), + ("is_completed", c_int), + ("arcs_sorted_in", c_int), + ("arcs_sorted_out", c_int), + ("fsm_state", c_void_p), + ("sigma", c_void_p), + ("medlookup", c_void_p) + ] + - _fields_ = [("name", c_char * 40), ("arity", c_int), ("arccount", c_int), ("statecount", c_int), ("linecount", c_int), ("finalcount", c_int), ("pathcount", c_longlong), ("is_deterministic", c_int), ("is_pruned", c_int), ("is_minimized", c_int), ("is_epsilon_free", c_int), ("is_loop_free", c_int), ("is_completed", c_int), ("arcs_sorted_in", c_int), ("arcs_sorted_out", c_int), ("fsm_state", c_void_p), ("sigma", c_void_p), ("medlookup", c_void_p)] - foma_fsm_parse_regex = foma.fsm_parse_regex foma_fsm_parse_regex.restype = POINTER(FSTstruct) foma_apply_init = foma.apply_init @@ -98,29 +118,33 @@ fsm_trie_done = foma.fsm_trie_done fsm_trie_done.restype = POINTER(FSTstruct) -class FSTnetworkdefinitions(object): +class FSTnetworkdefinitions(object): def __init__(self): self.defhandle = defined_networks_init(None) -class FSTfunctiondefinitions(object): +class FSTfunctiondefinitions(object): def __init__(self): self.deffhandle = defined_functions_init(None) - - -class FST(object): + +class FST(object): networkdefinitions = FSTnetworkdefinitions() functiondefinitions = FSTfunctiondefinitions() + # Generalize over Python2 and Python3 types + string_types = str if version_info[0] > 2 else basestring + text_type = str if version_info[0] > 2 else unicode + binary_type = bytes if version_info[0] > 2 else str + @classmethod def define(cls, definition, name): """Defines an FSM constant; can be supplied regex or existing FSM.""" name = cls.encode(name) if isinstance(definition, FST): retval = foma.add_defined(c_void_p(cls.networkdefinitions.defhandle), foma_fsm_copy(definition.fsthandle), c_char_p(name)) - elif isinstance(definition, basestring): + elif isinstance(definition, FST.string_type): regex = cls.encode(definition) retval = foma.add_defined(c_void_p(cls.networkdefinitions.defhandle), foma_fsm_parse_regex(c_char_p(regex), c_void_p(cls.networkdefinitions.defhandle), c_void_p(cls.functiondefinitions.deffhandle)), c_char_p(name)) else: @@ -132,9 +156,9 @@ # Prototype is a 2-tuple (name, (arg1name, ..., argname)) # Definition is regex using prototype variables name = cls.encode(prototype[0] + '(') - if isinstance(definition, basestring): + if isinstance(definition, FST.string_type): numargs = len(prototype[1]) - for i in xrange(numargs): + for i in range(numargs): definition = definition.replace(prototype[1][i], "@ARGUMENT0%i@" % (i+1)) regex = cls.encode(definition + ';') retval = foma.add_defined_function(c_void_p(cls.functiondefinitions.deffhandle), c_char_p(name), c_char_p(regex), c_int(numargs)) @@ -159,21 +183,33 @@ def load(cls, filename): """Load binary FSM from file.""" fsm = cls() - fsm.fsthandle = foma_fsm_read_binary_file(c_char_p(filename)) + fsm.fsthandle = foma_fsm_read_binary_file(c_char_p(FST.encode(filename))) if not fsm.fsthandle: raise ValueError("File error.") return fsm @staticmethod def encode(string): + # type: (Any) -> FST.binary_type """Makes sure str and unicode are converted.""" - if isinstance(string, unicode): + if isinstance(string, FST.text_type): return string.encode('utf8') - elif isinstance(string, str): + elif isinstance(string, FST.binary_type): return string else: - return str(string) - + return FST.encode(str(string)) + + @staticmethod + def decode(text): + if text is None: + return None + elif isinstance(text, FST.binary_type): + # Assume output is UTF-8 encoded: + return text.decode('UTF-8') + else: + assert isinstance(text, FST.text_type) + return text + def __init__(self, regex = False): if regex: self.regex = self.encode(regex) @@ -269,7 +305,7 @@ return False def __call__(self, other): - if isinstance(other, basestring): + if isinstance(other, FST.string_type): return FST("{" + other + "}").compose(self) else: return other.compose(self) @@ -301,7 +337,7 @@ if tokenize: yield output[:-1].split('\x07') else: - yield output + yield self.decode(output) if word: output = applyf(c_void_p(applyerhandle), None) else: @@ -467,11 +503,11 @@ def _fmt(self, word): cols = word - colchunks = [map(lambda z: len(z), word[x:x+self.numtapes]) for x in xrange(0, len(word), self.numtapes)] + colchunks = [map(lambda z: len(z), word[x:x+self.numtapes]) for x in range(0, len(word), self.numtapes)] col_widths = [max(x) for x in colchunks] format = ' '.join(['%%-%ds' % width for width in col_widths]) # string to rows - rows = [[word[y] for y in xrange(x, len(word), self.numtapes)] for x in xrange(self.numtapes)] + rows = [[word[y] for y in range(x, len(word), self.numtapes)] for x in range(self.numtapes)] s = '' for row in rows: #s += format % tuple(row) + '\n' @@ -487,7 +523,7 @@ foma_apply_set_space_symbol(c_void_p(applyerhandle), c_char_p(toksym)) output = applyf(c_void_p(applyerhandle)) while True: - if output == None: + if output is None: foma_apply_clear(c_void_p(applyerhandle)) return else: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/python/foma2js.py new/foma-0.9.18+git20200221.5e5521e/foma/python/foma2js.py --- old/foma-0.9.18+git20180511.bad2f09/foma/python/foma2js.py 1970-01-01 01:00:00.000000000 +0100 +++ new/foma-0.9.18+git20200221.5e5521e/foma/python/foma2js.py 2020-02-21 22:45:41.000000000 +0100 @@ -0,0 +1,140 @@ +#!/usr/bin/env python +"""Converts foma file to js array for use with Javascript runtime +Outputs a js array of all the transitions, indexed in the +input direction. This array can be passed to the js function +foma_apply_down() in foma_apply_down.js for stand-alone +transducer application.""" + +import sys +import os +import re +import argparse +import gzip +from enum import Enum +from collections import defaultdict + + +class Mode(Enum): + NONE = 0 + PROPS = 1 + SIGMA = 2 + STATES = 4 + + +def main(): + argparser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__) + argparser.add_argument('-n', '--name', help='Array variable name', default='myNet') + argparser.add_argument('file', help='Foma file') + args = argparser.parse_args() + with gzip.open(args.file) as gzfile: + lines = [line.decode('utf-8').strip() for line in gzfile.readlines()] + mode = Mode.NONE + num_nets = 0 + version = 0.0 + longest_symbol_length = 0 + props = {} + sigma = {} + trans = defaultdict(list) + finals = {} + RE_FOMA_NET = re.compile(r'.*##foma-net ([0-9]+\.[0-9]+)##') + RE_PROPS = re.compile(r'##props##') + RE_SIGMA = re.compile(r'##sigma##') + RE_STATES = re.compile(r'##states##') + RE_END = re.compile(r'##end##') + for line in lines: + match = RE_FOMA_NET.match(line) + if match: + version = float(match.group(1)) + num_nets += 1 + if num_nets > 1: + raise ValueError('Only one network per file supported') + continue + match = RE_PROPS.match(line) + if match: + mode = Mode.PROPS + continue + match = RE_SIGMA.match(line) + if match: + mode = Mode.SIGMA + continue + match = RE_STATES.match(line) + if match: + mode = Mode.STATES + continue + match = RE_END.match(line) + if match: + mode = Mode.NONE + continue + if mode is Mode.PROPS: + prop_names = ['arity', 'arccount', 'statecount', 'linecount', 'finalcount', 'pathcount', 'is_deterministic', 'is_pruned', 'is_minimized', 'is_epsilon_free', 'is_loop_free', 'extras', 'name'] + props = {k: v for k, v in zip(prop_names, line.split(' '))} + elif mode is Mode.STATES: + #state in out target final + transitions = tuple(map(int, line.split(' '))) + if transitions[0] == -1: + continue + if transitions[1] == -1 and len(transitions) == 4: + arr_state, _, _, arr_final = transitions + if arr_final == 1: + finals[arr_state] = 1 + continue + if len(transitions) == 5: + arr_state, arr_in, arr_out, arr_target, arr_final = transitions + if arr_final == 1: + finals[arr_state] = 1 + elif len(transitions) == 4: + arr_state, arr_in, arr_target, arr_final = transitions + arr_out = arr_in + if arr_final == 1: + finals[arr_state] = 1 + elif len(transitions) == 3: + arr_in, arr_out, arr_target = transitions + elif len(transitions) == 2: + arr_in, arr_target = transitions + arr_out = arr_in + trans_key = '{}|{}'.format(arr_state, sigma[arr_in]) + trans_value = '{{{}:\'{}\'}}'.format(arr_target, sigma[arr_out]) + trans[trans_key].append(trans_value) + elif mode is Mode.SIGMA: + tokens = line.split(' ') + number = int(tokens[0]) + symbol = tokens[1] if len(tokens) > 1 else '' + if symbol == '@_EPSILON_SYMBOL_@': + symbol = '' + if symbol == '@_IDENTITY_SYMBOL_@': + symbol = '@ID@' + if symbol == '@_UNKNOWN_SYMBOL_@': + symbol = '@UN@' + if '\'' in symbol: + symbol = symbol.replace('\'', '\\\'') + sigma[number] = symbol + if number > 2 and len(symbol) > longest_symbol_length: + longest_symbol_length = len(symbol) + elif mode is Mode.NONE: + raise ValueError('Format error') + + print('var {} = new Object;'.format(args.name)) + print('{}.t = Array;'.format(args.name)) + print('{}.f = Array;'.format(args.name)) + print('{}.s = Array;'.format(args.name)) + print() + + for key in trans: + state, inp = key.split('|') + if inp == '@UN@': + inp = '@ID@' + print('{}.t[{} + \'|\' + \'{}\'] = [{}];'.format(args.name, state, inp, ','.join(trans[key]))) + + for i in range(0, int(props['statecount'])+1): + if i in finals: + print('{}.f[{}] = 1;'.format(args.name, i)) + + for i in range(3, len(sigma)): + if i in sigma: + print('{}.s[\'{}\'] = {};'.format(args.name, sigma[i], i)) + + print('{}.maxlen = {} ;'.format(args.name, longest_symbol_length)) + + +if __name__ == "__main__": + main() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/python/test_foma.py new/foma-0.9.18+git20200221.5e5521e/foma/python/test_foma.py --- old/foma-0.9.18+git20180511.bad2f09/foma/python/test_foma.py 1970-01-01 01:00:00.000000000 +0100 +++ new/foma-0.9.18+git20200221.5e5521e/foma/python/test_foma.py 2020-02-21 22:45:41.000000000 +0100 @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# -*- coding: UTF-8 -*- + +""" +Test cases for Foma Python bindings. +""" + +import pytest +from foma import FST + + +def test_load_fst(): + fst = FST.load('ate.fsm') + assert isinstance(fst, FST) + + +def test_apply_fst(eat_fst): + result, = eat_fst.apply_up('ate') + assert result == 'eat+V+Past' + + +def test_apply_down(eat_fst): + result, = eat_fst.apply_down('eat+V+3P+Sg') + assert result == 'eats' + + [email protected] +def eat_fst(): + return FST.load('ate.fsm') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/python/tox.ini new/foma-0.9.18+git20200221.5e5521e/foma/python/tox.ini --- old/foma-0.9.18+git20180511.bad2f09/foma/python/tox.ini 1970-01-01 01:00:00.000000000 +0100 +++ new/foma-0.9.18+git20200221.5e5521e/foma/python/tox.ini 2020-02-21 22:45:41.000000000 +0100 @@ -0,0 +1,7 @@ +[tox] +envlist = py27,py36 +# Do not require setup.py +skipsdist = True +[testenv] +deps=pytest +commands=pytest diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foma-0.9.18+git20180511.bad2f09/foma/rewrite.c new/foma-0.9.18+git20200221.5e5521e/foma/rewrite.c --- old/foma-0.9.18+git20180511.bad2f09/foma/rewrite.c 2018-05-11 19:04:08.000000000 +0200 +++ new/foma-0.9.18+git20200221.5e5521e/foma/rewrite.c 2020-02-21 22:45:41.000000000 +0100 @@ -103,7 +103,7 @@ rb = xxcalloc(1, sizeof(struct rewrite_batch)); rb->rewrite_set = all_rules; rb->num_rules = num_rules; - rb->namestrings = xxmalloc(sizeof rb->namestrings * num_rules); + rb->namestrings = xxmalloc(sizeof *rb->namestrings * num_rules); for (i = 0; i < rb->num_rules; i++) { sprintf(rb->namestrings[i], "@#%04i@", i+1); }
