本文整理汇总了C#中Phrase.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Phrase.Add方法的具体用法?C# Phrase.Add怎么用?C# Phrase.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phrase
的用法示例。
在下文中一共展示了Phrase.Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static Phrase Parse(IFuzzyState state, Phrase phrase) {
Match regexMatch = TimeVariableTemporalPrimitiveToken.RegexMatch.Match(phrase.Text);
if (regexMatch.Success == true) {
int? hours = regexMatch.Groups["hours"].Value.Length > 0 ? int.Parse(regexMatch.Groups["hours"].Value) : 0;
int? minutes = regexMatch.Groups["minutes"].Value.Length > 0 ? int.Parse(regexMatch.Groups["minutes"].Value) : 0;
int? seconds = regexMatch.Groups["seconds"].Value.Length > 0 ? int.Parse(regexMatch.Groups["seconds"].Value) : 0;
if (String.Compare(regexMatch.Groups["meridiem"].Value, "pm", StringComparison.OrdinalIgnoreCase) == 0 && hours < 12) {
hours += 12;
}
else if (String.Compare(regexMatch.Groups["meridiem"].Value, "am", StringComparison.OrdinalIgnoreCase) == 0) {
if (hours == 12) {
hours = 0;
}
}
hours %= 24;
phrase.Add(new TimeVariableTemporalPrimitiveToken() {
Pattern = new FuzzyDateTimePattern() {
Rule = TimeType.Definitive,
Hour = (regexMatch.Groups["hours"].Value.Length > 0 ? hours : null),
Minute = (regexMatch.Groups["minutes"].Value.Length > 0 ? minutes : null),
Second = (regexMatch.Groups["seconds"].Value.Length > 0 ? seconds : null)
},
Text = phrase.Text,
Similarity = 100.0F
});
}
return phrase;
}
示例2: Parse
public static Phrase Parse(IFuzzyState state, Phrase phrase) {
if (phrase.Text.Length > 0 && phrase.Text.First() == '"' && phrase.Text.Last() == '"' && phrase.Refactoring == false) {
phrase.Add(new StringPrimitiveToken() {
Text = phrase.Text.Trim('"'),
Similarity = 80,
Value = phrase.Text.Trim('"')
});
}
return phrase;
}
示例3: Parse
public static Phrase Parse(IFuzzyState state, Phrase phrase) {
Match regexMatch = DateVariableTemporalPrimitiveToken.RegexMatch.Match(phrase.Text);
if (regexMatch.Success == true) {
DateTime dt;
if (DateTime.TryParse(phrase.Text, out dt) == true) {
phrase.Add(new DateVariableTemporalPrimitiveToken() {
Pattern = new FuzzyDateTimePattern() {
Rule = TimeType.Definitive,
Year = dt.Year,
Month = dt.Month,
Day = dt.Day
},
Text = phrase.Text,
Similarity = 100.0F
});
}
}
return phrase;
}
示例4: Process
/**
* Process the text so that it will render with a combination of fonts
* if needed.
* @param text the text
* @return a <CODE>Phrase</CODE> with one or more chunks
*/
public virtual Phrase Process(String text) {
if (fonts.Count == 0)
throw new ArgumentOutOfRangeException(MessageLocalization.GetComposedMessage("no.font.is.defined"));
char[] cc = text.ToCharArray();
int len = cc.Length;
StringBuilder sb = new StringBuilder();
Phrase ret = new Phrase();
currentFont = null;
for (int k = 0; k < len; ++k) {
Chunk newChunk = ProcessChar(cc, k, sb);
if (newChunk != null) {
ret.Add(newChunk);
}
}
if (sb.Length > 0) {
Chunk ck = new Chunk(sb.ToString(), currentFont ?? fonts[0]);
ret.Add(ck);
}
return ret;
}
示例5: GetPhrase
public static Phrase GetPhrase(Properties attributes)
{
Phrase phrase = new Phrase();
phrase.Font = FontFactory.GetFont(attributes);
String value;
value = attributes[ElementTags.LEADING];
if (value != null) {
phrase.Leading = float.Parse(value, NumberFormatInfo.InvariantInfo);
}
value = attributes[Markup.CSS_KEY_LINEHEIGHT];
if (value != null) {
phrase.Leading = Markup.ParseLength(value, Markup.DEFAULT_FONT_SIZE);
}
value = attributes[ElementTags.ITEXT];
if (value != null) {
Chunk chunk = new Chunk(value);
if ((value = attributes[ElementTags.GENERICTAG]) != null) {
chunk.SetGenericTag(value);
}
phrase.Add(chunk);
}
return phrase;
}
示例6: GetTokens
public static Phrase GetTokens(this Tree tree, Tree root = null, Rhetorica.Sentence sentence = null, string ignore = "", string punctuation = null, AnalyzerOptions options = AnalyzerOptions.None)
{
var tokens = new Phrase(sentence: sentence);
java.util.List leaves = tree.getLeaves();
for (java.util.Iterator i = leaves.iterator(); i.hasNext(); ) {
Tree leaf = (Tree)i.next();
string token = leaf.value().Trim();
Tree preterminal = leaf.parent(tree);
if (preterminal == null)
continue;
string tag = preterminal.value().Trim();
bool ignoreMeansInclude = options.HasFlag(AnalyzerOptions.IgnoreMeansInclude);
if (ignore != string.Empty) {
bool isMatch = Regex.IsMatch(token, ignore);
if (ignoreMeansInclude) {
if (!isMatch) continue;
}
else {
if (isMatch) continue;
}
}
bool omitPunctuation = options.HasFlag(AnalyzerOptions.OmitPunctuationTokens);
if (omitPunctuation) {
// Leave out certain types of punctuation:
bool isPunctuation = Regex.IsMatch(tag, punctuation ?? Analyzer.PunctuationPatterns)
|| Regex.IsMatch(token, punctuation ?? Analyzer.PunctuationPatterns);
if (isPunctuation) {
tokens.IsPunctuationOmitted = true;
continue;
}
// But also remove any straggler punctuation missed within a token...? Maybe not. Use RegExp 'FloatingPunctuationPatterns' if so.
}
root = root ?? tree;
int depth = root.depth() - root.depth(preterminal);
var characterEdges = new CharacterEdges(root.leftCharEdge(leaf), root.rightCharEdge(leaf));
tokens.Add(new Token(token, tag, depth, characterEdges));
}
return tokens;
}
示例7: ParsePhrase
/// <summary>
/// Parses a script from the specified resource.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="rawPhrase">The phrase which to parse.</param>
/// <returns>Returns the parsed script.</returns>
/// <exception cref="ParseScriptException">Thrown when an exception occurres while parsing the script.</exception>
private Phrase ParsePhrase(IMansionContext context, string rawPhrase)
{
// validate arguments
if (context == null)
throw new ArgumentNullException("context");
if (rawPhrase == null)
throw new ArgumentNullException("rawPhrase");
// create a new phrase
var phrase = new Phrase();
// tokenize the raw phrase into smaller sections
foreach (var token in tokenizer.Tokenize(context, rawPhrase))
{
// get the interpreter for this input
var interpreter = Election<ExpressionPartInterpreter, string>.Elect(context, interpreters, token);
// interpret the token
phrase.Add(interpreter.Interpret(context, token));
}
// return the parsed phrase
return phrase;
}
示例8: Process
/**
* Process the text so that it will render with a combination of fonts
* if needed.
* @param text the text
* @return a <CODE>Phrase</CODE> with one or more chunks
*/
public Phrase Process(String text)
{
int fsize = fonts.Count;
if (fsize == 0)
throw new ArgumentException("No font is defined.");
char[] cc = text.ToCharArray();
int len = cc.Length;
StringBuilder sb = new StringBuilder();
Font font = null;
int lastidx = -1;
Phrase ret = new Phrase();
for (int k = 0; k < len; ++k) {
char c = cc[k];
if (c == '\n' || c == '\r') {
sb.Append(c);
continue;
}
if (Utilities.IsSurrogatePair(cc, k)) {
int u = Utilities.ConvertToUtf32(cc, k);
for (int f = 0; f < fsize; ++f) {
font = (Font)fonts[f];
if (font.BaseFont.CharExists(u)) {
if (lastidx != f) {
if (sb.Length > 0 && lastidx != -1) {
Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx]);
ret.Add(ck);
sb.Length = 0;
}
lastidx = f;
}
sb.Append(c);
sb.Append(cc[++k]);
break;
}
}
}
else {
for (int f = 0; f < fsize; ++f) {
font = (Font)fonts[f];
if (font.BaseFont.CharExists(c)) {
if (lastidx != f) {
if (sb.Length > 0 && lastidx != -1) {
Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx]);
ret.Add(ck);
sb.Length = 0;
}
lastidx = f;
}
sb.Append(c);
break;
}
}
}
}
if (sb.Length > 0) {
Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx == -1 ? 0 : lastidx]);
ret.Add(ck);
}
return ret;
}