本文整理汇总了C#中Context.LookupAndAdd方法的典型用法代码示例。如果您正苦于以下问题:C# Context.LookupAndAdd方法的具体用法?C# Context.LookupAndAdd怎么用?C# Context.LookupAndAdd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.LookupAndAdd方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KnowPhrase
public static bool KnowPhrase(IParsedPhrase phrase, Context context, Memory memory)
{
GroupPhrase groupPhrase = new GroupPhrase(phrase);
IParsedPhrase datetime = groupPhrase.GetBranch(1);
Datum datum = new Datum(null, Relations.Relation.AtTime, memory.NewConcept(datetime), context.Weight);
context.LookupAndAdd<List<Datum>>("$knowPartials", new List<Datum>()).Add(datum);
return true;
}
示例2: Produce
public override bool Produce(Context context, IContinuation succ, IFailure fail)
{
string word = StarUtilities.ProducedCode(context, tagger, parser);
Datum datum;
if (word == "past")
datum = new Datum(null, Relations.Relation.Tense, memory.past, context.Weight);
else if (word.Contains(" "))
datum = new Datum(null, Relations.Relation.Tense, memory.NewConcept(word, Concept.Kind.Entity), context.Weight);
else
{
bool isPast = verbs.GetInflection(word) == Verbs.Convert.ext_Ved;
if (isPast)
datum = new Datum(null, Relations.Relation.Tense, memory.past, context.Weight);
else
datum = new Datum(null, Relations.Relation.Tense, memory.now, context.Weight);
}
context.LookupAndAdd<List<Datum>>("$knowPartials", new List<Datum>()).Add(datum);
succ.Continue(new Context(context, new List<IContent>()), fail);
return true;
}
示例3: Know
public static void Know(Memory memory, Context context, Relations.Relation kind, IParsedPhrase phrase, double weight, ConceptTranslator produceTranslator)
{
Concept concept = produceTranslator.GetConcept(phrase);
Datum datum = new Datum(null, kind, concept, weight);
context.LookupAndAdd<List<Datum>>("$knowPartials", new List<Datum>()).Add(datum);
}
示例4: CompletePartials
public Concept CompletePartials(Context context)
{
if (context.Contents.Count == 0)
return null;
IParsedPhrase phrase = StarUtilities.ProducedPhrase(context, tagger, parser);
if (phrase == null)
{
// cannot do!
context.Map["$knowPartials"] = new List<Datum>();
return null;
}
Concept concept = memory.NewConcept(phrase);
List<Datum> completes = context.LookupAndAdd<List<Datum>>("$knowCompletes", new List<Datum>());
List<Datum> data = context.LookupDefaulted<List<Datum>>("$knowPartials", new List<Datum>());
foreach (Datum datum in data)
completes.Add(memory.Know(concept, datum));
context.Map["$knowPartials"] = new List<Datum>();
return concept;
}
示例5: Evaluate
public override bool Evaluate()
{
// Look through my concepts for a possible match
List<IContent> contents = context.Contents;
if (contents.Count == 1) {
if (contents[0] is Variable)
{
Variable check = (Variable)contents[0];
// If we already have a concept in mind, just check its data
Concept left = context.LookupDefaulted<Concept>("$knowConcept", null);
if (left != null)
{
List<Datum> data = memory.GetData(left);
foreach (Datum datum in data)
{
if (datum.Left == left && kinds.Contains(datum.Relation) && check.Match(context, datum.Right))
{
List<Datum> completes = context.LookupAndAdd<List<Datum>>("$knowCompletes", new List<Datum>());
completes.Add(datum);
succ.Continue(new Context(context, new List<IContent>()), fail);
return true;
}
}
// Can't match anything!
fail.Fail("Initial variable didn't match anything", succ);
return true;
}
// Does anything here match?
for (int ii = 0; ii < directchecks.Count; ii++)
{
bool matched = kinds.Contains(directchecks[ii].Relation);
if (matched)
{
matched = check.Match(context, directchecks[ii].Right);
if (propfunc != null) // always do propfuncs, but only affect matched if failed
matched = check.Match(context, directchecks[ii].Right, propfunc, propargs) || matched;
}
if (matched)
{
Context child = new Context(context, new List<IContent>());
child.Map["$knowConcept"] = directchecks[ii].Left;
List<Datum> completes = child.LookupAndAdd<List<Datum>>("$knowCompletes", new List<Datum>());
completes.Add(directchecks[ii]);
// Make a clone of ourselves, if this fails
succ.Continue(child, MakeContinuingFailure(ii));
return true;
}
}
}
else if (contents[0].Name == "*" || contents[0].Name == "_")
{
// If we already have a concept in mind, just check its data
Concept left = context.LookupDefaulted<Concept>("$knowConcept", null);
if (left != null)
{
List<Datum> data = memory.GetData(left);
foreach (Datum datum in data)
{
if (datum.Left == left && kinds.Contains(datum.Relation))
{
List<IContent> words = new List<IContent>();
if (!datum.Right.IsUnknown)
words.Add(new Word(datum.Right.Name));
context.Map.Add(StarUtilities.NextStarName(context, contents[0].Name), words);
List<Datum> completes = context.LookupAndAdd<List<Datum>>("$knowCompletes", new List<Datum>());
completes.Add(datum);
succ.Continue(new Context(context, new List<IContent>()), fail);
return true;
}
}
// Can't match anything!
fail.Fail("Could not find a matching datum", succ);
return true;
}
// Does anything here match?
for (int ii = 0; ii < directchecks.Count; ii++)
if (kinds.Contains(directchecks[ii].Relation))
{
Context child = new Context(context, new List<IContent>());
List<IContent> words = new List<IContent>();
if (!directchecks[ii].Right.IsUnknown)
words.Add(new Word(directchecks[ii].Right.Name));
child.Map.Add(StarUtilities.NextStarName(child, contents[0].Name), words);
child.Map["$knowConcept"] = directchecks[ii].Left;
List<Datum> completes = child.LookupAndAdd<List<Datum>>("$knowCompletes", new List<Datum>());
completes.Add(directchecks[ii]);
//.........这里部分代码省略.........