void GrammarBlockVisitor.IfClusterGrammarBlock(ClusterGrammarBlock cluster) { foreach (var block in cluster.blocks) { GrammarBlockUtils.VisitGrammarBlock(block, this); } }
float TimeExpresssionToFloatSec(GrammarBlock timeExpression) { var vis = new TimeCountVisitor(); GrammarBlockUtils.VisitGrammarBlock(timeExpression, vis); return(vis.result); }
public BehaverBridge(Behaver _behaverFront, BridgeHelperFactoryBridge _helperFactory) { helperFactory = _helperFactory; behaverFront = _behaverFront; matchAttributeCallback = (newAttributeGBlockPtr) => { try { var gBlock = NativeGrammarBlockUtils.GBlockPtrToGBlock(newAttributeGBlockPtr); var bf = this.behaverFront; return((int)behaverFront.MatchAttribue(gBlock)); } catch (System.Exception e) { Debug.LogError(e); return((int)AttributeMatchResult.NEUTRAL); } }; setBehaviorCallback = (behaviorExpression, listener) => { try { var gBlock = NativeGrammarBlockUtils.GBlockPtrToGBlock(behaviorExpression); behaverFront.ReadyBehavior(GrammarBlockUtils.GBlockToBExpression(gBlock), new NativeBehaviorRequestListener(listener, helperFactory)); Debug.Log("READY Set Behaver Front behavior: " + gBlock.cluster.blocks[1].unit.word); } catch (Exception e) { Debug.LogError(e); } }; checkBehaviorCallback = (behaviorExpression, listener) => { try { var gBlock = NativeGrammarBlockUtils.GBlockPtrToGBlock(behaviorExpression); behaverFront.ReadyCheckBehavior(GrammarBlockUtils.GBlockToBExpression(gBlock), new NativeBehaviorCheckRequestListener(listener, helperFactory)); Debug.Log("READY Check Behaver Front behavior: " + gBlock.cluster.blocks[1].unit.word); } catch (Exception e) { Debug.LogError(e); } }; }
//public Taker dependencyBehavers; AttributeMatchResult AttributeMatcher.MatchAttribue(GrammarBlock attribute) { if (actualBehaver != null) { return(actualBehaver.MatchAttribue(attribute)); } return(GrammarBlockUtils.IsUnit(attribute, baseGUnit.word) ? AttributeMatchResult.POSITIVE : AttributeMatchResult.NEUTRAL); }
AttributeMatchResult AttributeMatcher.MatchAttribue(GrammarBlock attribute) { if (GrammarBlockUtils.IsUnit(attribute, "system")) { return(AttributeMatchResult.POSITIVE); } return(AttributeMatchResult.NEUTRAL); }
void Taker <GrammarBlock> .Take(GrammarBlock item) { GrammarBlockUtils.ForEach(item, "Unreadable", (gBlock) => { string result = fileName + " : "; GrammarBlockUtils.ForEachUnits((gBlock), (gUnit) => result += " " + gUnit.word); parent.parent.OnUnreadableFound.Invoke(result); }); parent.parent.bAnalyzer.bAnlys.AnalyzeBehavior(item, this); }
public void SetPronounSolution(GrammarBlock sourceGBlock, GBlockConvertListener listener) { GrammarBlockUtils.DeepSeek(sourceGBlock, StdMetaInfos.nominalBlock.word, (gBlock) => { //acutual noun found if (!GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.pronoun.word)) { pronouc.dict["they"] = listener.subBlockConverter.ConvertGBlock(gBlock, listener).result; } }, true); }
void Giver <IEnumerable <BehaverAgent>, GrammarBlock> .Give(GrammarBlock key, Taker <IEnumerable <BehaverAgent> > colletor) { if (GrammarBlockUtils.IsUnit(key, nameOnCreate)) { var inst = Utilities.ConsistentInstantiate(seekingAgentPrefab); inst.behaverAttribute = seekingAgentPrefab.behaverAttribute; inst.gameObject.SetActive(true); colletor.Take(new List <BehaverAgent> { inst.behaverAgent }); } }
void Taker <GrammarBlock> .Take(GrammarBlock item) { GrammarBlockUtils.ForEach(item, "Unreadable", (gBlock) => { string result = ""; GrammarBlockUtils.ForEachUnits((gBlock), (gUnit) => result += " " + gUnit.word); parent.parent.OnUnreadableFound.Invoke(result); }); parent.parent.OnSucceedEvent.Invoke(new AnalysisResult { gBlock = item, name = fileName, sourceText = sourceText }); parent.parent.bAnalyzer.bAnlys.AnalyzeBehavior(item, this); }
AttributeMatchResult AttributeMatcher.MatchAttribue(GrammarBlock attribute) { var checker = new MultiMatchingGBlockVisitor { candidates = candidates }; GrammarBlockUtils.VisitGrammarBlock(attribute, checker); if (checker.hasOne && !checker.hasUnmatch) { return(AttributeMatchResult.POSITIVE); } return(AttributeMatchResult.NEGATIVE); }
void Giver<IEnumerable<BehaverAgent>, GrammarBlock>.Give(GrammarBlock key, Taker<IEnumerable<BehaverAgent>> colletor) { if (GrammarBlockUtils.IsUnit(key, "button")) { GrammarBlockUtils.ForEachUnits( key.modifier, (unit) => { MonoBBehaverAgent newButton; nameToButtonDict[unit.word] = newButton = GameObject.Instantiate(textButtonPrefab); newButton.GetComponent<TextViewer>().SetText(unit.word); newButton.GetComponent<BehaverAgent>().TryFittingSpace(new Vector3(0.4f, 1f, 1)); colletor.Take(new List<BehaverAgent> { newButton.behaverAgent }); } ); } }
bool AssetImplementCustomizer <MonoBBehaverEquipper> .MatchAsset(MonoBBehaverEquipper implementedAsset, GrammarBlock gBlock) { var checker = new JustCheckEquipListener(); if (GrammarBlockUtils.ShallowSeek(gBlock.metaInfo, "SV") == null) { implementedAsset.behaverEquipper.EquipBehaverByBehavior(new StdBehaviorExpression(gBlock.cluster.blocks[0], gBlock.cluster.blocks[1].unit), checker); } else { implementedAsset.behaverEquipper.EquipBehaverByAttribute(gBlock, checker); } return(checker.canEquip); }
void BehaverEquipListener.OnEquipSubBehaver(MonoBUnityBehaver baseBehaver) { canEquip = true; var instance = Utilities.ConsistentInstantiate(baseBehaver, customBehaverInstance.transform); customBehaverInstance.baseBehaver = instance; if (!GrammarBlockUtils.HasMetaInfo(bExpr.asGBlock, StdMetaInfos.conditionSV.word)) { instance.behaver.ReadyBehavior(bExpr, unityBRSupport); } else { instance.behaver.ReadyCheckBehavior(bExpr, unityBRSupport); } }
UnityBehaviorCheckTrigger UnityBehaviorChecker.ReadyCheckBehavior(BehaviorExpression bExpr, UnityBehaviorReadySupport listener) { UnityBehaviorCheckTrigger trigger = null; if (GrammarBlockUtils.IsUnit(bExpr.verb, "hit")) { var button = GrammarBlockUtils.ShallowSeek(bExpr.verb.modifier, "button"); GrammarBlockUtils.ForEachUnits( button.modifier, (unit) => { trigger = FindObjectOfType <GUIBehaver>().NewHitButtonCheckTrigger(unit.word); } ); return(trigger); } return(trigger); }
UnityBehaviorTrigger UnityBehaviorSetter.ReadyBehavior(BehaviorExpression behavior, UnityBehaviorReadySupport support) { if (CaseInsensitiveComparer.Equals(behavior.verb.word, "show")) { var howMany = GrammarBlockUtils.ShallowSeekModifier(behavior.verb, "how many"); if (howMany != null) { var trigger = new ShowNumberTrigger { modifier = behavior.verb.modifier, textViewerPrefab = textViewerPrefab }; return(trigger); } else { //stub : show something } } else if (CaseInsensitiveComparer.Equals(behavior.verb.word, "clear")) { if (GrammarBlockUtils.ShallowSeekModifier(behavior.verb, "space") != null) { var trigger = new ClearAllSpaces { spaceDistributer = spaceD }; return(trigger); } } else if (CaseInsensitiveComparer.Equals(behavior.verb.word, "quit")) { return(new QuitTrigger()); } else if (CaseInsensitiveComparer.Equals(behavior.verb.word, "fade in")) { return(new FadeTrigger { fadeDelta = -0.01f, fadeProcess = fadeProcess }); } else if (CaseInsensitiveComparer.Equals(behavior.verb.word, "fade out")) { return(new FadeTrigger { fadeDelta = 0.01f, fadeProcess = fadeProcess }); } return(null); }
public static Vector3 LocalPosition(BAgentSpace space, BehaviorExpression bExpr) { if (bExpr.verb.modifier != null) { var at_where = GrammarBlockUtils.ShallowSeek(bExpr.verb.modifier, "at"); if (at_where != null) { if (at_where.modifier.unit != null) { var positionDesc = at_where.modifier.unit.word.Split('-'); if (positionDesc.Length == 2) { var posOffset = Vector3.zero; posOffset.z = 0.5f; if (positionDesc[0] == "lower") { posOffset.y = 0.25f; } else if (positionDesc[0] == "middle") { posOffset.y = 0.5f; } else if (positionDesc[0] == "upper") { posOffset.y = 0.75f; } if (positionDesc[1] == "left") { posOffset.x = 0.25f; } else if (positionDesc[1] == "center") { posOffset.x = 0.5f; } else if (positionDesc[1] == "right") { posOffset.x = 0.75f; } return(space.lowerBoundary + Vector3.Scale(space.upperBoundary - space.lowerBoundary, posOffset)); } } } } return(Vector3.zero); }
void BehaviorAnalyzer.AnalyzeBehavior(GrammarBlock behaviorExpressionByGBlock, Taker <BehaviorTriggerSet> listener) { //ensure behaver { var metaDepVis = new MetaInfoDependentGrammarBlockVisitor { doDeepSeek = true, doDeepSeekModifier = true }; metaDepVis.metaToVis[StdMetaInfos.nominalBlock.word] = new EnsureBehaver { behaverGiver = stdGiver }; GrammarBlockUtils.VisitGrammarBlock(behaviorExpressionByGBlock, metaDepVis); } //cereate behavior trigger { var rootTrigger = new StdCompositeBehaviorTrigger(); var namedCBTrigger = new Dictionary <string, CompositeBehaviorTrigger>(); var processor = new SentenceBlockRecursiveProcessor { subSentenceBehaviorTaker = rootTrigger, behaverSetCheck = bSetCheck, namedCBTriggers = namedCBTrigger, support = new StdBehaviorReadySupport { assetMediator = assetMediator.assetMed } }; processor.GrammarBlockCommon(behaviorExpressionByGBlock); if (rootTrigger.bTriggers.Count > 0 || namedCBTrigger.Count > 0) { List <NameAndBTrigger> namedTriggers = null; if (namedCBTrigger.Count > 0) { namedTriggers = new List <NameAndBTrigger>(); foreach (var pair in namedCBTrigger) { namedTriggers.Add(new NameAndBTrigger { name = pair.Key, bTrigger = pair.Value }); } } var result = new BehaviorTriggerSet { rootTrigger = rootTrigger.bTriggers.Count > 0 ? rootTrigger : null, namedTriggers = namedTriggers }; listener.Take(result); } } }
void GrammarBlockVisitor.IfGrammarUnit(GrammarUnit gUnit) { if (gUnit.modifier != null) { GBlockVisitor_GetFloat numberFetcher = new GBlockVisitor_GetFloat(); if (string.Compare(gUnit.word, "hour", true) == 0) { GrammarBlockUtils.VisitGrammarBlock(gUnit.modifier, numberFetcher); result += numberFetcher.numberFloat * 60 * 60; } else if (string.Compare(gUnit.word, "minute", true) == 0) { GrammarBlockUtils.VisitGrammarBlock(gUnit.modifier, numberFetcher); result += numberFetcher.numberFloat * 60; } else if (string.Compare(gUnit.word, "second", true) == 0) { GrammarBlockUtils.VisitGrammarBlock(gUnit.modifier, numberFetcher); result += numberFetcher.numberFloat; } } }
GBlockConvertResult GBlockConverter.ConvertGBlock(GrammarBlock sourceGBlock, GBlockConvertListener listener) { if (!GrammarBlockUtils.IsUnit(sourceGBlock, "each")) { return(default(GBlockConvertResult)); } if (!GrammarBlockUtils.IsUnit(sourceGBlock.modifier, "turn")) { return(default(GBlockConvertResult)); } var newSubject = listener.subBlockConverter.ConvertGBlock(sourceGBlock.modifier, listener).result; var newVerb = new StdMutableGUnit { word = "begin" }; (newVerb as MutableGrammarBlock).AddMetaInfo(StdMetaInfos.verbalBlock); MutableClusterGrammarBlock newSV = new StdMutableClusterGBlock(); newSV.AddBlock(newSubject); newSV.AddBlock(newVerb); newSV.AddMetaInfo(StdMetaInfos.conditionSV); return(new GBlockConvertResult(true, newSV)); }
GBlockConvertResult GBlockConverter.ConvertGBlock(GrammarBlock sourceGBlock, GBlockConvertListener listener) { if (!GrammarBlockUtils.HasMetaInfo(sourceGBlock, StdMetaInfos.pronoun.word)) { return(default(GBlockConvertResult)); } if (dict.TryGetValue(sourceGBlock.unit.word, out var value)) { var clusterGBC = new ClusterGBlockConverter { converters = new List <GBlockConverter> { new GBlockConverter_GUnitFilter { filteringString = StdMetaInfos.pronoun.word }, listener.metaConverter } }; GBlockConvertUtility.ApplyModAndMeta(value, sourceGBlock, listener, clusterGBC); return(new GBlockConvertResult { didConvert = true, result = value }); } return(default(GBlockConvertResult)); }
GrammarBlock ImmediateGiver <GrammarBlock, GrammarBlock> .Give(GrammarBlock key) { var listener = new MixedGBlockConvertListener(); var rootConv = new RootGBlockConverter(); listener._metaConverter = GBlockConverter_Default.instance; listener._modConverter = rootConv; listener._subBlockConverter = rootConv; if (GrammarBlockUtils.HasMetaInfo(key, StdMetaInfos.sentenceCluster.word) && key.cluster != null) { var newCluster = new StdMutableClusterGBlock(); foreach (var sentence in key.cluster.blocks) { rootConv.SetPronounSolution(sentence, listener); var converterSetnence = (listener as GBlockConvertListener).subBlockConverter.ConvertGBlock(sentence, listener); (newCluster as MutableClusterGrammarBlock).AddBlock(converterSetnence.result); } GBlockConvertUtility.ApplyModAndMeta(newCluster as MutableGrammarBlock, key, listener); return(newCluster); } rootConv.SetPronounSolution(key, listener); return((rootConv as GBlockConverter).ConvertGBlock(key, listener).result); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { #region get input log.LogInformation("C# HTTP trigger function processed a request."); var form = await req.ReadFormAsync(); var files = form.Files; var ewordsFile = files["ewords"]; MemoryStream ms = new MemoryStream(); ewordsFile.OpenReadStream().CopyTo(ms); var content = ms.ToArray(); #endregion string nLang = System.Text.Encoding.UTF8.GetString(content); NaturalLanguageProcessor processor = new ExampleNLangProcessor("BasicEnglishDictionary.json"); var collector = new EasyAsyncCollector <GrammarBlock>(); processor.PerformSyntacticProcess(nLang, collector); var jsonStr = GrammarBlockUtils.ToJson(collector.collected); var json = System.Text.Encoding.UTF8.GetBytes(jsonStr); return(json != null ? (ActionResult) new FileContentResult(json, "text/html") : new BadRequestObjectResult("Please pass a name on the query string or in the request body")); }
public GrammarBlockVisualizeUnit CreateVisualizeUnit(GrammarBlock gBlock, GrammarBlock parent = null) { var visUnit = Instantiate(visualizerUnitPrefab); if (gBlock.unit != null) { Destroy(visUnit.horizontalClusterRoot.gameObject); Destroy(visUnit.verticalClusterRoot.gameObject); if (GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.quoteBlock.word) || GrammarBlockUtils.HasMetaInfo(parent, StdMetaInfos.quoteBlock.word)) { visUnit.word.GetComponentInChildren <UnityEngine.UI.Text>().text = " \"" + gBlock.unit.word + "\" "; } else { visUnit.word.GetComponentInChildren <UnityEngine.UI.Text>().text = gBlock.unit.word; } if (GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.nominalBlock.word) || GrammarBlockUtils.HasMetaInfo(parent, StdMetaInfos.nominalBlock.word)) { visUnit.contentBG.color = Color.red; } if (GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.verbalBlock.word) || GrammarBlockUtils.HasMetaInfo(parent, StdMetaInfos.verbalBlock.word)) { visUnit.contentBG.color = Color.blue; } } else { Destroy(visUnit.word.gameObject); UnityEngine.RectTransform clusterRoot = null; if (GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.sentenceCluster.word)) { Destroy(visUnit.horizontalClusterRoot.gameObject); clusterRoot = visUnit.verticalClusterRoot; if (parent != null) { visUnit.contentBG.color = sentenceClusterColor; } else { visUnit.contentBG.color = otherClusterColor; } } else { Destroy(visUnit.verticalClusterRoot.gameObject); clusterRoot = visUnit.horizontalClusterRoot; if (GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.nominalBlock.word)) { visUnit.contentBG.color = nominalClusterColor; } else if (GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.verbalBlock.word)) { visUnit.contentBG.color = verbalClusterColor; } else if (GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.sv.word) || GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.conditionSV.word)) { visUnit.contentBG.color = svSentenceColor; } else { visUnit.contentBG.color = otherClusterColor; } } foreach (var subBlock in gBlock.cluster.blocks) { var newSubVisUnit = CreateVisualizeUnit(subBlock, gBlock); newSubVisUnit.transform.SetParent(clusterRoot, false); } } if (gBlock.modifier == null) { Destroy(visUnit.modifierRoot.gameObject); } else { var modVisUnit = CreateVisualizeUnit(gBlock.modifier); modVisUnit.transform.SetParent(visUnit.modifierRoot, false); //modVisUnit.transform.localScale = Vector3.Scale(modVisUnit.transform.localScale, Vector3.one * 0.8f); //if (gBlock.cluster != null) modVisUnit.AddBackGround().color = modColor; visUnit.AddBackGround().color = modifiedBlockColor; } if (GrammarBlockUtils.HasMetaInfo(gBlock, StdMetaInfos.conditionSV.word)) { visUnit.metaRoot.GetComponentInChildren <UnityEngine.UI.Text>().text = " If "; } else { Destroy(visUnit.metaRoot.gameObject); } return(visUnit); }
AttributeMatchResult AttributeMatcher.MatchAttribue(GrammarBlock attribute) { return(GrammarBlockUtils.IsUnit(attribute, "player") ? AttributeMatchResult.POSITIVE : AttributeMatchResult.NEGATIVE); }
AttributeMatchResult AttributeMatcher.MatchAttribue(GrammarBlock attribute) { return(GrammarBlockUtils.IsUnit(attribute, behaverAttribute.word) ? AttributeMatchResult.POSITIVE : AttributeMatchResult.NEUTRAL); }
GBlockConvertResult GBlockConverter.ConvertGBlock(GrammarBlock sourceGBlock, GBlockConvertListener listener) { //only applly to SV or Condition SV if (!GrammarBlockUtils.HasMetaInfo(sourceGBlock, StdMetaInfos.sv.word) && !GrammarBlockUtils.HasMetaInfo(sourceGBlock, StdMetaInfos.conditionSV.word)) { return(default(GBlockConvertResult)); } //search passive be List <GrammarUnit> passiveVerbList = null; var originalSubject = sourceGBlock.cluster.blocks[0]; var convertedSubject = listener.subBlockConverter.ConvertGBlock(originalSubject, listener).result; var originalVerbs = sourceGBlock.cluster.blocks[1]; GrammarBlockUtils.DeepForEachBlockUnit( originalVerbs, (mainVerbUnit) => { if (GrammarBlockUtils.IsUnit(mainVerbUnit, "be")) { GrammarBlockUtils.DeepForEachBlockUnit( mainVerbUnit.modifier, (contentVerbUnit) => { if (passiveVerbList == null) { passiveVerbList = new List <GrammarUnit>(); } passiveVerbList.Add(contentVerbUnit); }, StdMetaInfos.verbalBlock.word ); } }, StdMetaInfos.verbalBlock.word ); //no passive verb found if (passiveVerbList == null) { return(default(GBlockConvertResult)); } //search normal verbs #if false List <GrammarBlock> normalVerbList = null; GrammarBlockUtils.ForEachUnits( originalVerbs, (gUnit) => { if (GrammarBlockUtils.ShallowSeekByMetaInfo(sourceGBlock.cluster.blocks[1], StdMetaInfos.verbalBlock.word) != null) { if (normalVerbList == null) { normalVerbList = new List <GrammarBlock>(); } normalVerbList.Add(gUnit); } }, StdMetaInfos.modifierCluster.word ); #endif MutableGrammarBlock converted = null; #region passive only if (passiveVerbList.Count > 0) { var newSVCluster = new StdMutableClusterGBlock { }; StdMutableClusterGBlock newSV = null; foreach (var passiveVerb in passiveVerbList) { newSV = new StdMutableClusterGBlock { }; (newSV as MutableClusterGrammarBlock).AddBlock(defaultSubject); var activizedVerb = listener.subBlockConverter.ConvertGBlock(passiveVerb, listener).result; activizedVerb.AddModifier(convertedSubject); (newSV as MutableClusterGrammarBlock).AddBlock(activizedVerb); (newSVCluster as MutableClusterGrammarBlock).AddBlock(newSV); (newSV as MutableClusterGrammarBlock).AddMetaInfo(sourceGBlock.metaInfo); } if (passiveVerbList.Count == 1) { converted = newSV; GBlockConvertUtility.ApplyModAndMeta(converted, sourceGBlock, listener); } else { converted = newSVCluster; var convLis = new MixedGBlockConvertListener { _baseLisetner = listener, _metaConverter = new ClusterGBlockConverter { converters = new List <GBlockConverter> { new GBlockConverter_Replace { number = new Dictionary <string, GrammarBlock> { { StdMetaInfos.sv.word, StdMetaInfos.sentenceCluster }, { StdMetaInfos.conditionSV.word, StdMetaInfos.sentenceCluster } } }, listener.metaConverter } } }; GBlockConvertUtility.ApplyModAndMeta(converted, sourceGBlock, convLis); } } #endregion #region no result if (converted == null) { return(default(GBlockConvertResult)); } return(new GBlockConvertResult(true, converted)); #endregion }