From 606e3e38b8a830dbbe65963ebf6c5ce7866b7800 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Tue, 18 Mar 2014 01:41:17 -0400 Subject: star function --- utils/star.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 utils/star.h (limited to 'utils/star.h') diff --git a/utils/star.h b/utils/star.h new file mode 100644 index 00000000..3295112c --- /dev/null +++ b/utils/star.h @@ -0,0 +1,12 @@ +#ifndef _STAR_H_ +#define _STAR_H_ + +template +T star(const T& x) { + if (!x) return T(); + if (x > T(1)) return std::numeric_limits::infinity(); + if (x < -T(1)) return -std::numeric_limits::infinity(); + return T(1) / (T(1) - x); +} + +#endif -- cgit v1.2.3 From 55beb71dbbfe8421a8e8be9d2d7868a5d87d77d5 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Tue, 18 Mar 2014 01:55:19 -0400 Subject: star bool --- utils/star.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'utils/star.h') diff --git a/utils/star.h b/utils/star.h index 3295112c..e7358ffa 100644 --- a/utils/star.h +++ b/utils/star.h @@ -1,6 +1,8 @@ #ifndef _STAR_H_ #define _STAR_H_ +// star(x) computes the infinite sum x^0 + x^1 + x^2 + ... + template T star(const T& x) { if (!x) return T(); @@ -9,4 +11,8 @@ T star(const T& x) { return T(1) / (T(1) - x); } +bool star(bool x) { + return x; +} + #endif -- cgit v1.2.3 From 2a9ee1febae6a63173f74ae24e2bfe439e409525 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Tue, 18 Mar 2014 02:05:25 -0400 Subject: chris edits --- corpus/support/tokenizer.pl | 4 ++++ utils/exp_semiring.h | 2 +- utils/logval.h | 2 +- utils/star.h | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'utils/star.h') diff --git a/corpus/support/tokenizer.pl b/corpus/support/tokenizer.pl index 7771201f..f57bc87a 100755 --- a/corpus/support/tokenizer.pl +++ b/corpus/support/tokenizer.pl @@ -240,6 +240,10 @@ sub proc_token { return $token; } + if($token =~ /^\d+(.\d+)+(亿|百万|万|千)?$/){ + return $token; + } + ## 1,234,345.34 if($token =~ /^\d+(\.\d{3})*,\d+$/){ ## number diff --git a/utils/exp_semiring.h b/utils/exp_semiring.h index 7572ccf5..26a22071 100644 --- a/utils/exp_semiring.h +++ b/utils/exp_semiring.h @@ -56,7 +56,7 @@ const PRPair operator*(const PRPair& a, const PRPair& b) { } template -const PRPair star(const PRPair& x) { +inline const PRPair star(const PRPair& x) { const P pstar = star(x.p); return PRPair(pstar, pstar * x.r * pstar); } diff --git a/utils/logval.h b/utils/logval.h index 7f1e1024..0c9ee982 100644 --- a/utils/logval.h +++ b/utils/logval.h @@ -244,7 +244,7 @@ template std::size_t hash_value(const LogVal& x) { return x.hash_impl(); } template -LogVal star(LogVal x) { +inline LogVal star(LogVal x) { if (x.is_0()) return x; if (x.v_ >= 0) { x.v_ = std::numeric_limits::infinity(); diff --git a/utils/star.h b/utils/star.h index e7358ffa..21977dc9 100644 --- a/utils/star.h +++ b/utils/star.h @@ -4,14 +4,14 @@ // star(x) computes the infinite sum x^0 + x^1 + x^2 + ... template -T star(const T& x) { +inline T star(const T& x) { if (!x) return T(); if (x > T(1)) return std::numeric_limits::infinity(); if (x < -T(1)) return -std::numeric_limits::infinity(); return T(1) / (T(1) - x); } -bool star(bool x) { +inline bool star(bool x) { return x; } -- cgit v1.2.3