/** * Sets the vp features. * * @param wp * The xml Verb Phrase object. * @param p * the internal VP object to get features from xml object. */ private void setVPFeatures(wrapper.XmlVPPhraseSpec wp, VPPhraseSpec p) { if (wp.FORM != null) { Enum.TryParse(wp.FORM.ToString(), out Form form); p.setFeature(Feature.FORM, form); } if (wp.PERSON != null) { p.setFeature(Feature.PERSON, wp.PERSON); } if (wp.TENSE != null) { Enum.TryParse(wp.TENSE.ToString(), out Form tense); p.setFeature(Feature.TENSE, tense); } if (wp.MODAL != null) { p.setFeature(Feature.MODAL, wp.MODAL); } p.setFeature(Feature.AGGREGATE_AUXILIARY, wp.AGGREGATEAUXILIARY); p.setFeature(Feature.NEGATED, wp.NEGATED); p.setFeature(Feature.PASSIVE, wp.PASSIVE); p.setFeature(Feature.PERFECT, wp.PERFECT); p.setFeature(Feature.PROGRESSIVE, wp.PROGRESSIVE); p.setFeature(Feature.SUPPRESS_GENITIVE_IN_GERUND, wp.SUPPRESSGENITIVEINGERUND); p.setFeature(Feature.SUPRESSED_COMPLEMENTISER, wp.SUPRESSEDCOMPLEMENTISER); }
/** * Unwrap a <code>simplenlg.xmlrealiser.wrapper.NLGElement</code> and map it * to a <code>simplenlg.framework.NLGElement</code> * * @param wps * The wrapper object * @return the NLGElement */ public virtual NLGElement UnwrapNLGElement(wrapper.XmlNLGElement wps) { if (wps == null) { return(null); } if (wps is wrapper.XmlDocumentElement) { return((NLGElement)UnwrapDocumentElement((wrapper.XmlDocumentElement)wps)); } // Handle coordinate phrase specs first, which will cause recursion. NLGElement cp = UnwrapCoordinatePhraseSpec(wps); if (cp != null) { return(cp); } // Literal text. if (wps is wrapper.XmlStringElement) { wrapper.XmlStringElement wp = (wrapper.XmlStringElement)wps; NLGElement p = factory.createStringElement(wp.Val); return(p); } // WordElements (delegate to UnwrapWordElement) -- useful to have // because it is called by unWrapPhraseComponents, and pre/post mods // might be WordElements if (wps is XmlWordElement) { return(UnwrapWordElement((XmlWordElement)wps)); } // Sentence else if (wps is wrapper.XmlSPhraseSpec) { wrapper.XmlSPhraseSpec wp = (wrapper.XmlSPhraseSpec)wps; SPhraseSpec sp = factory.createClause(); NLGElement vp = null; List <NLGElement> subjects = new List <NLGElement>(); foreach (wrapper.XmlNLGElement p in wp.Subj) { NLGElement p1 = UnwrapNLGElement(p); checkFunction(DiscourseFunction.SUBJECT, p1); subjects.Add(p1); } if (subjects.Any()) { sp.setFeature(InternalFeature.SUBJECTS, subjects); } if (wp.Vp != null) { vp = UnwrapNLGElement(wp.Vp); sp.VerbPhrase = vp; } if (wp.CuePhrase != null) { NLGElement cue = UnwrapNLGElement(wp.CuePhrase); cue.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.CUE_PHRASE); sp.setFeature(Feature.CUE_PHRASE, cue); } if (wp.COMPLEMENTISER != null) { sp.setFeature(Feature.COMPLEMENTISER, wp.COMPLEMENTISER); } setSFeatures(wp, sp, vp); // Common phrase components. UnwrapPhraseComponents(sp, wps); return(sp); } // Phrases else if (wps is wrapper.XmlPhraseElement) { wrapper.XmlPhraseElement we = (wrapper.XmlPhraseElement)wps; PhraseElement hp = null; XmlWordElement w = we.Head; NLGElement head = UnwrapWordElement(w); // NLGElement head; // simplenlg.xmlrealiser.wrapper.XmlNLGElement w = // we.getHeadstring(); // check whether we have a stringelement or wordelement as head // if(w == null) { // w = we.getHeadword(); // head = UnwrapWordElement((XmlWordElement) w); // // } else { // head = factory.createStringElement(((XmlStringElement) // w).getVal()); // } // Noun Phrase if (wps is wrapper.XmlNPPhraseSpec) { wrapper.XmlNPPhraseSpec wp = (wrapper.XmlNPPhraseSpec)wps; NPPhraseSpec p = factory.createNounPhrase(head); hp = p; if (wp.Spec != null) { // p.setSpecifier(UnwrapWordElement(wp.getSpec())); wrapper.XmlNLGElement spec = wp.Spec; if (spec is XmlWordElement) { WordElement specifier = (WordElement)UnwrapWordElement((XmlWordElement)spec); if (specifier != null) { p.setSpecifier(specifier); } } else { p.setSpecifier(UnwrapNLGElement(spec)); } } setNPFeatures(wp, p); } // Adjective Phrase else if (wps is wrapper.XmlAdjPhraseSpec) { wrapper.XmlAdjPhraseSpec wp = (wrapper.XmlAdjPhraseSpec)wps; AdjPhraseSpec p = factory.createAdjectivePhrase(head); hp = p; p.setFeature(Feature.IS_COMPARATIVE, wp.ISCOMPARATIVE); p.setFeature(Feature.IS_SUPERLATIVE, wp.ISSUPERLATIVE); } // Prepositional Phrase else if (wps is wrapper.XmlPPPhraseSpec) { PPPhraseSpec p = factory.createPrepositionPhrase(head); hp = p; } // Adverb Phrase else if (wps is wrapper.XmlAdvPhraseSpec) { wrapper.XmlAdvPhraseSpec wp = (wrapper.XmlAdvPhraseSpec)wps; AdvPhraseSpec p = factory.createAdverbPhrase(); p.setHead(head); hp = p; p.setFeature(Feature.IS_COMPARATIVE, wp.ISCOMPARATIVE); p.setFeature(Feature.IS_SUPERLATIVE, wp.ISSUPERLATIVE); } // Verb Phrase else if (wps is wrapper.XmlVPPhraseSpec) { wrapper.XmlVPPhraseSpec wp = (wrapper.XmlVPPhraseSpec)wps; VPPhraseSpec p = factory.createVerbPhrase(head); hp = p; setVPFeatures(wp, p); } // Common phrase components. UnwrapPhraseComponents(hp, wps); // set the discourse function, if defined if (we.DiscourseFunction != null) { DiscourseFunction func; Enum.TryParse(we.DiscourseFunction.ToString(), out func); hp.setFeature(InternalFeature.DISCOURSE_FUNCTION, func); } // check the appositive feature bool?appositive = we.Appositive; if (appositive != null) { hp.setFeature(Feature.APPOSITIVE, appositive); } return(hp); } return(null); }