Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
            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);
                }
            }
Exemplo n.º 3
0
 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));
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
    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);
    }
Exemplo n.º 6
0
        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
        }