コード例 #1
0
ファイル: StdGBlockConverters.cs プロジェクト: iwaag/AGBLang
 GBlockConvertResult GBlockConverter.ConvertGBlock(GrammarBlock sourceGBlock, GBlockConvertListener listener)
 {
     if (sourceGBlock.cluster != null)
     {
         var newClusterGB = new StdMutableClusterGBlock();
         foreach (var subGB in sourceGBlock.cluster.blocks)
         {
             var convertedSub = listener.subBlockConverter.ConvertGBlock(subGB, listener).result;
             if (convertedSub != null)
             {
                 newClusterGB.subBlocks.Add(convertedSub);
             }
         }
         GBlockConvertUtility.ApplyModAndMeta(newClusterGB, sourceGBlock, listener);
         return(new GBlockConvertResult(true, newClusterGB));
     }
     else if (sourceGBlock.unit != null)
     {
         var newGUnit = new StdMutableGUnit {
             word = sourceGBlock.unit.word
         };
         GBlockConvertUtility.ApplyModAndMeta(newGUnit, sourceGBlock, listener);
         return(new GBlockConvertResult(true, newGUnit));
     }
     return(default(GBlockConvertResult));
 }
コード例 #2
0
ファイル: StdGBlockConverters.cs プロジェクト: iwaag/AGBLang
 GBlockConvertResult GBlockConverter.ConvertGBlock(GrammarBlock sourceGBlock, GBlockConvertListener listener)
 {
     if (sourceGBlock.unit == null)
     {
         return(default(GBlockConvertResult));
     }
     if (number.TryGetValue(sourceGBlock.unit.word, out var value))
     {
         if (value == null)
         {
             return(new GBlockConvertResult(true, null));
         }
         //doubt : using sub block converter?
         var newMGBlock = listener.subBlockConverter.ConvertGBlock(value, listener);
         GBlockConvertUtility.ApplyModAndMeta(newMGBlock.result, sourceGBlock, listener);
         return(new GBlockConvertResult(true, newMGBlock.result));
     }
     return(default(GBlockConvertResult));
 }
コード例 #3
0
ファイル: StdGBlockConverters.cs プロジェクト: iwaag/AGBLang
 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));
 }
コード例 #4
0
ファイル: StdGBlockFilter.cs プロジェクト: iwaag/AGBLang
        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);
        }
コード例 #5
0
ファイル: StdGBlockConverters.cs プロジェクト: iwaag/AGBLang
        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
        }