示例#1
0
        /**
         * Applies backward conjunction reduction to two NLGElements e1 and e2,
         * succeeding only if they are clauses (that is, e1.getCategory() ==
         * e2.getCategory == {@link simplenlg.framework.PhraseCategory#CLAUSE}).
         *
         * @param previous
         *            the first phrase
         * @param next
         *            the second phrase
         * @return a coordinate phrase if aggregation is successful,
         *         <code>null</code> otherwise
         */

        public override INLGElement apply(INLGElement previous, INLGElement next)
        {
            var success = false;

            if (previous.getCategory().enumType == (int)PhraseCategoryEnum.CLAUSE &&
                next.getCategory().enumType == (int)PhraseCategoryEnum.CLAUSE &&
                PhraseChecker.nonePassive(new List <INLGElement> {
                previous, next
            }))
            {
                var rightPeriphery = PhraseChecker.rightPeriphery(new List <INLGElement> {
                    previous, next
                });

                foreach (var pair in rightPeriphery)
                {
                    if (pair.lemmaIdentical())
                    {
                        pair.elideLeftmost();
                        success = true;
                    }
                }
            }

            return(success
            ? factory.createCoordinatedPhrase(previous, next)
            : null);
        }
示例#2
0
        /**
         * Applies aggregation to two NLGElements e1 and e2, succeeding only if they
         * are clauses (that is, e1.getCategory() == e2.getCategory ==
         * {@link simplenlg.framework.PhraseCategory#CLAUSE}).
         */

        public override INLGElement apply(INLGElement previous, INLGElement next)
        {
            INLGElement aggregated = null;

            if (previous.getCategory().enumType == (int)PhraseCategoryEnum.CLAUSE &&
                next.getCategory().enumType == (int)PhraseCategoryEnum.CLAUSE &&
                PhraseChecker.nonePassive(new List <INLGElement> {
                previous, next
            }) &&
                !PhraseChecker.expletiveSubjects(new List <INLGElement> {
                previous, next
            }))
            {
                // case 1: identical sentences: remove the current
                if (PhraseChecker.sameSentences(new List <INLGElement> {
                    previous, next
                }))
                {
                    aggregated = previous;

                    // case 2: subjects identical: coordinate VPs
                }
                else if (PhraseChecker.sameFrontMods(new List <INLGElement> {
                    previous, next
                }) &&
                         PhraseChecker.sameSubjects(new List <INLGElement> {
                    previous, next
                }) &&
                         PhraseChecker.samePostMods(new List <INLGElement> {
                    previous, next
                }))
                {
                    aggregated = factory.createClause();
                    aggregated.setFeature(InternalFeature.SUBJECTS.ToString(), previous
                                          .getFeatureAsElementList(InternalFeature.SUBJECTS.ToString()));
                    aggregated.setFeature(InternalFeature.FRONT_MODIFIERS.ToString(), previous
                                          .getFeatureAsElement(InternalFeature.FRONT_MODIFIERS.ToString()));
                    aggregated.setFeature(Feature.CUE_PHRASE.ToString(), previous
                                          .getFeatureAsElement(Feature.CUE_PHRASE.ToString()));
                    aggregated
                    .setFeature(
                        InternalFeature.POSTMODIFIERS.ToString(),
                        previous
                        .getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString()));
                    INLGElement vp;

                    // case 2.1: VPs have different arguments but same
                    // head & mods
                    if (!PhraseChecker.sameVPArgs(new List <INLGElement> {
                        previous, next
                    }) &&
                        PhraseChecker.sameVPHead(new List <INLGElement> {
                        previous, next
                    }) &&
                        PhraseChecker.sameVPModifiers(new List <INLGElement> {
                        previous, next
                    }))
                    {
                        var vp1 = previous
                                  .getFeatureAsElement(InternalFeature.VERB_PHRASE.ToString());
                        vp = factory.createVerbPhrase();
                        vp.setFeature(InternalFeature.HEAD.ToString(), vp1
                                      .getFeatureAsElement(InternalFeature.HEAD.ToString()));
                        vp.setFeature(InternalFeature.COMPLEMENTS.ToString(),
                                      vp1.getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString()));
                        vp.setFeature(
                            InternalFeature.PREMODIFIERS.ToString(),
                            vp1
                            .getFeatureAsElementList(InternalFeature.PREMODIFIERS.ToString()));
                        vp.setFeature(
                            InternalFeature.POSTMODIFIERS.ToString(),
                            vp1
                            .getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString()));

                        // case 2.2: just create a coordinate vP
                    }
                    else
                    {
                        var vp1 = previous
                                  .getFeatureAsElement(InternalFeature.VERB_PHRASE.ToString());
                        var vp2 = next
                                  .getFeatureAsElement(InternalFeature.VERB_PHRASE.ToString());
                        vp = factory.createCoordinatedPhrase(vp1, vp2);

                        // case 2.3: expletive subjects
                    }

                    aggregated.setFeature(InternalFeature.VERB_PHRASE.ToString(), vp);

                    // case 3: identical VPs: conjoin subjects and front
                    // modifiers
                }
                else if (PhraseChecker.sameFrontMods(new List <INLGElement> {
                    previous, next
                }) &&
                         PhraseChecker.sameVP(new List <INLGElement> {
                    previous, next
                }) &&
                         PhraseChecker.samePostMods(new List <INLGElement> {
                    previous, next
                }))
                {
                    aggregated = factory.createClause();
                    aggregated
                    .setFeature(
                        InternalFeature.FRONT_MODIFIERS.ToString(),
                        previous
                        .getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS.ToString()));
                    var subjects = factory
                                   .createCoordinatedPhrase();
                    subjects.setCategory(new PhraseCategory_NOUN_PHRASE());
                    var allSubjects = previous
                                      .getFeatureAsElementList(InternalFeature.SUBJECTS.ToString());
                    allSubjects.addAll(next
                                       .getFeatureAsElementList(InternalFeature.SUBJECTS.ToString()));

                    foreach (var subj in allSubjects)
                    {
                        subjects.addCoordinate(subj);
                    }

                    aggregated.setFeature(InternalFeature.SUBJECTS.ToString(), subjects);
                    aggregated
                    .setFeature(
                        InternalFeature.POSTMODIFIERS.ToString(),
                        previous
                        .getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString()));
                    aggregated.setFeature(InternalFeature.VERB_PHRASE.ToString(), previous
                                          .getFeature(InternalFeature.VERB_PHRASE.ToString()));
                }
            }

            return(aggregated);
        }