public new void setUp() { list2Realisation = new StringBuilder("* in the room").append("\n* ").append(list1Realisation).append("\n").ToString(); // need to set formatter for realiser (set to null in the test // superclass) this.realiser.setFormatter(new TextFormatter()); // a couple phrases as list items listItem1 = this.phraseFactory.createListItem(this.inTheRoom); listItem2 = this.phraseFactory .createListItem(this.behindTheCurtain); listItem3 = this.phraseFactory.createListItem(this.onTheRock); // a simple depth-1 list of phrases list1 = this.phraseFactory .createList(new List <INLGElement> { listItem1, listItem2 }); /* a list consisting of one phrase (depth-1) + a list )(depth-2) * list2 = this.phraseFactory.createList( * new List<NLGElement> { new List<NLGElement> * { * listItem3, * this.phraseFactory.createListItem(list1) * }}); */ }
public Measurement(DocumentElement element, Size size, Thickness margin) { Subs = new Measurements(); Element = element; Size = size; Margin = margin; }
public override void setUp() { base.setUp(); // need to set formatter for realiser (set to null in the test superclass) realiser.Formatter = new TextFormatter(); // a couple phrases as list items listItem1 = phraseFactory.createListItem(inTheRoom); listItem2 = phraseFactory.createListItem(behindTheCurtain); listItem3 = phraseFactory.createListItem(onTheRock); // a simple depth-1 list of phrases list1 = phraseFactory.createList(new List <DocumentElement> { listItem1, listItem2 }); // a list consisting of one phrase (depth-1) + a list )(depth-2) list2 = phraseFactory.createList(new List <DocumentElement> { listItem3, phraseFactory.createListItem(list1) }); }
public void ReadTaxonomy(BasketRepository basketRepository, XmlReader reader, Taxonomy taxonomy) { var document = new DocumentElement(reader); var rootElement = document.LockOn("taxonomy"); this.ReadRoot(basketRepository, rootElement, taxonomy); }
public virtual void enumeratedList() { Lexicon lexicon = Lexicon.DefaultLexicon; NLGFactory nlgFactory = new NLGFactory(lexicon); Realiser realiser = new Realiser(lexicon); realiser.Formatter = new HTMLFormatter(); DocumentElement document = nlgFactory.createDocument("Document"); DocumentElement paragraph = nlgFactory.createParagraph(); DocumentElement list = nlgFactory.createEnumeratedList(); DocumentElement item1 = nlgFactory.createListItem(); DocumentElement item2 = nlgFactory.createListItem(); DocumentElement sentence1 = nlgFactory.createSentence("this", "be", "the first sentence"); DocumentElement sentence2 = nlgFactory.createSentence("this", "be", "the second sentence"); item1.addComponent(sentence1); item2.addComponent(sentence2); list.addComponent(item1); list.addComponent(item2); paragraph.addComponent(list); document.addComponent(paragraph); string expectedOutput = "<h1>Document</h1>" + "<p>" + "<ol>" + "<li>This is the first sentence.</li>" + "<li>This is the second sentence.</li>" + "</ol>" + "</p>"; string realisedOutput = realiser.realise(document).Realisation; Assert.AreEqual(expectedOutput, realisedOutput); }
public AddDocumentContainer(string projectName, string name, DocumentElement document, IEnumerable <string> folders = default) { this.Document = document; this.ProjectName = projectName; this.Name = name; this.Folders = folders; }
/// <summary> /// 重置所有的属性,包括Id。一般情况下是从外部导入或复制时调用。 /// </summary> public void ResetAllProperty(bool isRemoveContent, bool isHomeType) { XmlNodeList snipNodes = DocumentElement.SelectNodes("//snip"); foreach (XmlNode snipNode in snipNodes) { XmlElement snipEle = (XmlElement)snipNode; snipEle.SetAttribute("id", Utility.Guid.NewGuid()); if (snipEle.GetAttribute("type").ToLower() == PageSnipType.Content.ToString().ToLower()) { if (isHomeType) { snipEle.SetAttribute("type", PageSnipType.None.ToString()); snipEle.SetAttribute("hasSnip", false.ToString()); XmlUtilService.RemoveAllChilds(snipEle); continue; } if (isRemoveContent) { XmlUtilService.RemoveAllChilds((XmlElement)snipEle.SelectSingleNode("parts")); continue; } } XmlNodeList partNodes = snipEle.SelectNodes("//part"); foreach (XmlNode partNode in partNodes) { XmlElement partEle = (XmlElement)partNode; partEle.SetAttribute("partId", XmlUtilService.CreateIncreaseId()); } } }
private Template CreateTemplate(XmlNode templateNode) { if (templateNode == null) { throw new ArgumentNullException("templateNode"); } XmlNodeList colorNodeList = templateNode.SelectNodes("OpenTemplater:Colors/OpenTemplater:Color", _xmlNamespaceManager); IDictionary <string, ColorSet> colorDictionary = CreateColors(colorNodeList); XmlNodeList fontNodeList = templateNode.SelectNodes("OpenTemplater:Fonts/OpenTemplater:Font", _xmlNamespaceManager); XmlNode fontsCollectionNode = templateNode.SelectSingleNode("OpenTemplater:Fonts", _xmlNamespaceManager); if (fontsCollectionNode != null) { if (fontsCollectionNode.Attributes != null) { string basePath = fontsCollectionNode.Attributes["basePath"].Value; IDictionary <string, FontSet> fontDictionary = CreateFonts(fontNodeList, basePath); DocumentElement document = CreateDocument(templateNode.SelectSingleNode("OpenTemplater:Document", _xmlNamespaceManager)); string author = string.Empty; XmlNode authorNode = templateNode.SelectSingleNode("OpenTemplater:Author", _xmlNamespaceManager); if (authorNode != null) { author = authorNode.InnerText; } return(new Template(document, author, colorDictionary, fontDictionary)); } } throw new NullReferenceException("Cannot find fonts in template"); }
public async Task <DocumentTree> ParseFile(Stream file) { using (StreamReader sr = new StreamReader(file)) { var text = await sr.ReadToEndAsync(); var element = new DocumentElement { Text = text, Type = ElementType.Paragraph }; // construct document tree return(new DocumentTree { RootSegment = new DocumentSegment { RootElement = new DocumentElement { Text = string.Empty, Type = ElementType.Root }, Children = new List <DocumentSegment> { new DocumentSegment { RootElement = element, Children = null } } } }); } }
/** * Realise. * * @param wt * the wt * @return the string * @throws XMLRealiserException * the xML realiser exception */ public static string realise(wrapper.XmlDocumentElement wt) { string output = ""; if (wt != null) { try { if (lexicon == null) { lexicon = Lexicon.DefaultLexicon; } UnWrapper w = new UnWrapper(lexicon); DocumentElement t = w.UnwrapDocumentElement(wt); if (t != null) { Realiser r = new Realiser(lexicon); r.initialise(); NLGElement tr = r.realise(t); output = tr.Realisation; } } catch (Exception e) { throw new XMLRealiserException("NLG XMLRealiser Error", e); } } return output; }
public IBasket ReadBasket(Int32 basketId, String definitionXml, CountryRepository countryRepository) { IBasket result; using (var reader = XmlReader.Create(new StringReader(definitionXml))) { var document = new DocumentElement(reader); var expectedElementNames = new String[] { RegionBasket }; var someElement = document.MultilockOn(expectedElementNames); switch (someElement.Name) { case RegionBasket: { result = this.ReadRegionBasket(someElement, basketId, countryRepository); break; } default: { throw new ApplicationException("Anthough \"" + someElement.Name + "\" is an expected XML element of some basket type, there is no handler for reading it."); } } } return(result); }
public void DeserializeTaxonomy(XmlReader reader, BasketRepository basketRepository, CountryRepository countryRepository, Taxonomy taxonomy) { var document = new DocumentElement(reader); var rootElement = document.LockOn("taxonomy"); this.ReadRoot(rootElement, basketRepository, countryRepository, taxonomy); }
public virtual void section14_Test() { Lexicon lexicon = Lexicon.DefaultLexicon; // default simplenlg lexicon NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon Realiser realiser = new Realiser(lexicon); SPhraseSpec p1 = nlgFactory.createClause("Mary", "chase", "the monkey"); SPhraseSpec p2 = nlgFactory.createClause("The monkey", "fight back"); SPhraseSpec p3 = nlgFactory.createClause("Mary", "be", "nervous"); DocumentElement s1 = nlgFactory.createSentence(p1); DocumentElement s2 = nlgFactory.createSentence(p2); DocumentElement s3 = nlgFactory.createSentence(p3); DocumentElement par1 = nlgFactory.createParagraph(new List <DocumentElement> { s1, s2, s3 }); string output14a = realiser.realise(par1).Realisation; Assert.AreEqual("Mary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14a); DocumentElement section = nlgFactory.createSection("The Trials and Tribulation of Mary and the Monkey"); section.addComponent(par1); string output14b = realiser.realise(section).Realisation; Assert.AreEqual( "The Trials and Tribulation of Mary and the Monkey\nMary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14b); }
void InsertToolboxItemAttributes(WidgetParser parser, CodeRefactorer cref) { Dictionary <string, IType> tb_items = parser.GetToolboxItems(); foreach (string clsname in ObjectNames) { if (tb_items.ContainsKey(clsname)) { continue; } IType cls = parser.GetClass(clsname); if (cls == null) { continue; } cref.AddAttribute(cls, "System.ComponentModel.ToolboxItem", true); XmlElement elem = DocumentElement.SelectSingleNode("object[@type='" + clsname + "']") as XmlElement; if (elem != null && elem.HasAttribute("palette-category")) { cref.AddAttribute(cls, "System.ComponentModel.Category", elem.GetAttribute("palette-category")); } } }
static void Center(DocumentElement block) { if (block.Parent != null) { block.Parent.HorizontalAlignment = HorizontalAlignment.Center; } }
public virtual void testComplementiserPassivePerfectFeatures_PastTense() { setUp(); realiser.Lexicon = lexicon; PhraseElement inner = phraseFactory.createClause("I", "play", "poker"); inner.setFeature(Feature.TENSE, Tense.PAST); inner.setFeature(Feature.COMPLEMENTISER, "where"); PhraseElement house = phraseFactory.createNounPhrase("the", "house"); house.addComplement(inner); SPhraseSpec outer = phraseFactory.createClause(null, "abandon", house); outer.addPostModifier("since 1986"); outer.setFeature(Feature.PASSIVE, true); outer.setFeature(Feature.PERFECT, true); DocumentElement sentence = docFactory.createSentence(outer); NLGElement realised = realiser.realise(sentence); // Retrieve the realisation and dump it to the console Assert.AreEqual("The house where I played poker has been abandoned since 1986.", realised.Realisation); }
public virtual void testProgressiveComplementiserFeatures_PastTense() { phraseFactory.Lexicon = lexicon; NLGElement sandwich = phraseFactory.createNounPhrase(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN), "sandwich"); sandwich.Plural = true; PhraseElement first = phraseFactory.createClause("I", "make", sandwich); first.setFeature(Feature.TENSE, Tense.PAST); first.setFeature(Feature.PROGRESSIVE, true); first.Plural = false; PhraseElement second = phraseFactory.createClause("the mayonnaise", "run out"); second.setFeature(Feature.TENSE, Tense.PAST); second.setFeature(Feature.COMPLEMENTISER, "when"); first.addComplement(second); DocumentElement sentence = docFactory.createSentence(first); NLGElement realised = realiser.realise(sentence); // Retrieve the realisation and dump it to the console Assert.AreEqual("I was making sandwiches when the mayonnaise ran out.", realised.Realisation); }
private static void SetFixedBlock(CompilerState state, DocumentElement content, FixedPosition position) { var block = new FixedBlock(content) { Position = position }; if (position.HasFlag(FixedPosition.Bottom)) { block.Classes.Add("footer"); } else if (position.HasFlag(FixedPosition.Top)) { block.Classes.Add("header"); } for (int i = 0; i < state.Document.PageItems.Count; i++) { var item = state.Document.PageItems[i]; if (item is FixedBlock fix && fix.Position == position) { state.Document.PageItems.RemoveAt(i); break; } } state.Document.PageItems.Add(block); }
public virtual void testComplementiserFeatureInACoordinatePhrase_PastTense() { phraseFactory.Lexicon = lexicon; NLGElement dave = phraseFactory.createWord("Dave Bus", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); NLGElement albert = phraseFactory.createWord("Albert", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(dave, albert); PhraseElement born = phraseFactory.createClause(coord1, "be", "born"); born.setFeature(Feature.TENSE, Tense.PAST); born.addPostModifier("in"); born.setFeature(Feature.COMPLEMENTISER, "which"); PhraseElement theHouse = phraseFactory.createNounPhrase("the", "house"); theHouse.addComplement(born); PhraseElement clause = phraseFactory.createClause(theHouse, "be", phraseFactory.createPrepositionPhrase("in", "Edinburgh")); DocumentElement sentence = docFactory.createSentence(clause); NLGElement realised = realiser.realise(sentence); // Retrieve the realisation and dump it to the console Assert.AreEqual("The house which Dave Bus and Albert were born in is in Edinburgh.", realised.Realisation); }
private static DocumentElement[,] CopyCanvas(Layer layer) { var layerStateCopy = new DocumentElement[layer.Width, layer.Height]; Array.Copy(layer.Elements, layerStateCopy, layer.Width * layer.Height); return(layerStateCopy); }
XmlElement AddProduct() { XmlElement productElement = CreateWixElement("Product"); DocumentElement.AppendChild(productElement); return(productElement); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void PopulateProperties() { PackageName = DocumentElement.GetAttribute("package"); XmlNode applicationNode = SelectSingleNode("/manifest/application"); IsApplication = (applicationNode != null) && (applicationNode.Attributes.Count > 0); }
/// <summary> /// Delete multiple nodes /// </summary> /// <param name="xPath">xPath to the nodes to be deleted</param> /// <returns></returns> public bool DeleteNodes(string xPath) { if (DocumentElement == null) { throw new Exception("DocumentElemnt is null"); } return(DeleteNodes(DocumentElement.SelectNodes(xPath))); }
/// <summary> /// Addes an attribute and attribute value to a node that the xPath resolves to /// </summary> /// <param name="xPath">XPath of the node to add the attribute and attribute value to</param> /// <param name="attributeName">Name of the attribute to add</param> /// <param name="attributeValue">Value of the attribute being added</param> public void AddAttribute(string xPath, string attributeName, string attributeValue) { if (DocumentElement == null) { throw new Exception("DocumentElemnt is null"); } AddAttribute(DocumentElement.SelectSingleNode(xPath), attributeName, attributeValue); }
/// <summary> /// Adds a node to root named by xPath /// </summary> /// <param name="xPath"></param> /// <param name="nodeName"></param> /// <param name="nodeValue"></param> /// <returns>XmlNode added</returns> public XmlNode AddNode(string xPath, string nodeName, string nodeValue) { if (DocumentElement == null) { throw new Exception("DocumentElemnt is null"); } return(AddNode(DocumentElement.SelectSingleNode(xPath), CreateNode(nodeName, nodeValue))); }
public void SetConnectionString(string connectionString) { var node = DocumentElement.SelectSingleNode("connectionStrings"); if (node != null) { node.SelectSingleNode("add[@name=\"SiteSqlServer\"]").Attributes["connectionString"].InnerText = connectionString; } }
public virtual void multipleNLGElementListRealiserTest() { List <NLGElement> elements = new List <NLGElement>(); // Create test NLGElements to realize: // "The cat jumping on the counter." DocumentElement sentence1 = nlgFactory.createSentence(); NPPhraseSpec subject_1 = nlgFactory.createNounPhrase("the", "cat"); VPPhraseSpec verb_1 = nlgFactory.createVerbPhrase("jump"); verb_1.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE); PPPhraseSpec prep_1 = nlgFactory.createPrepositionPhrase(); NPPhraseSpec object_1 = nlgFactory.createNounPhrase(); object_1.setDeterminer("the"); object_1.setNoun("counter"); prep_1.addComplement(object_1); prep_1.setPreposition("on"); SPhraseSpec clause_1 = nlgFactory.createClause(); clause_1.setSubject(subject_1); clause_1.VerbPhrase = verb_1; clause_1.setObject(prep_1); sentence1.addComponent(clause_1); // "The dog running on the counter." DocumentElement sentence2 = nlgFactory.createSentence(); NPPhraseSpec subject_2 = nlgFactory.createNounPhrase("the", "dog"); VPPhraseSpec verb_2 = nlgFactory.createVerbPhrase("run"); verb_2.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE); PPPhraseSpec prep_2 = nlgFactory.createPrepositionPhrase(); NPPhraseSpec object_2 = nlgFactory.createNounPhrase(); object_2.setDeterminer("the"); object_2.setNoun("counter"); prep_2.addComplement(object_2); prep_2.setPreposition("on"); SPhraseSpec clause_2 = nlgFactory.createClause(); clause_2.setSubject(subject_2); clause_2.VerbPhrase = verb_2; clause_2.setObject(prep_2); sentence2.addComponent(clause_2); elements.Add(sentence1); elements.Add(sentence2); IList <NLGElement> realisedElements = realiser.realise(elements); Assert.IsNotNull(realisedElements); Assert.AreEqual(2, realisedElements.Count); Assert.AreEqual("The cat jumping on the counter.", realisedElements[0].Realisation); Assert.AreEqual("The dog running on the counter.", realisedElements[1].Realisation); }
public void multipleNLGElementListRealiserTest() { List <INLGElement> elements = new List <INLGElement>(); // Create test NLGElements to realize: // "The cat jumping on the counter." DocumentElement sentence1 = SetupForRealiserTest.phraseFactory.createSentence(); NPPhraseSpec subject_1 = SetupForRealiserTest.phraseFactory.createNounPhrase("the", "cat"); VPPhraseSpec verb_1 = SetupForRealiserTest.phraseFactory.createVerbPhrase("jump"); verb_1.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE); PPPhraseSpec prep_1 = SetupForRealiserTest.phraseFactory.createPrepositionPhrase(); NPPhraseSpec object_1 = SetupForRealiserTest.phraseFactory.createNounPhrase(); object_1.setDeterminer("the"); object_1.setNoun("counter"); prep_1.addComplement(object_1); prep_1.setPreposition("on"); SPhraseSpec clause_1 = SetupForRealiserTest.phraseFactory.createClause(); clause_1.setSubject(subject_1); clause_1.setVerbPhrase(verb_1); clause_1.setObject(prep_1); sentence1.addComponent(clause_1); // "The dog running on the counter." DocumentElement sentence2 = SetupForRealiserTest.phraseFactory.createSentence(); NPPhraseSpec subject_2 = SetupForRealiserTest.phraseFactory.createNounPhrase("the", "dog"); VPPhraseSpec verb_2 = SetupForRealiserTest.phraseFactory.createVerbPhrase("run"); verb_2.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE); PPPhraseSpec prep_2 = SetupForRealiserTest.phraseFactory.createPrepositionPhrase(); NPPhraseSpec object_2 = SetupForRealiserTest.phraseFactory.createNounPhrase(); object_2.setDeterminer("the"); object_2.setNoun("counter"); prep_2.addComplement(object_2); prep_2.setPreposition("on"); SPhraseSpec clause_2 = SetupForRealiserTest.phraseFactory.createClause(); clause_2.setSubject(subject_2); clause_2.setVerbPhrase(verb_2); clause_2.setObject(prep_2); sentence2.addComponent(clause_2); elements.add(sentence1); elements.add(sentence2); List <INLGElement> realisedElements = SetupForRealiserTest.realiser.realise(elements); Assert.IsNotNull(realisedElements); Assert.AreEqual(2, realisedElements.size()); Assert.AreEqual("The cat jumping on the counter.", realisedElements.get(0).getRealisation()); Assert.AreEqual("The dog running on the counter.", realisedElements.get(1).getRealisation()); }
private void WriteElement <T>(DocumentElement element, Action <T> Writer) where T : DocumentElement { var e = element as T; if (e != null) { Writer(e); } }
static void Center(DocumentElement block) { if (block.Parent is Panel panel) { for (int i = 0; i < panel.Elements.Count; i++) { panel.Elements[i].Style.Set(StyleKeys.HorizontalAlignment, HorizontalAlignment.Center); } } }
protected override void CopyContentFromOverride(DocumentElement fromElement) { CustomRangeEnd other = (CustomRangeEnd)fromElement; // Copy your custom properties from other to this here. }
protected override void CopyContentFromOverride(DocumentElement fromElement) { this.Name = ((RecipeRangeStart)fromElement).Name; }
public void CodeSyntax_XNodeInterpreter_BuildAndAppend() { var doc = new DocumentElement(); var expected1 = PropertyElement.Create("FirstName", "Peter"); var expected2 = PropertyElement.Create("LastName", "Åslund"); doc.SetProperty(expected1); doc.SetProperty(expected2); var actual1 = doc.CreateInterpreter().GetChild(0).To<XElement>().GetNode(); var actual2 = doc.CreateInterpreter().GetChildAs<XElement>(1).GetNode(); Assert.AreSame(expected1, actual1); Assert.AreSame(expected2, actual2); }
protected override void CopyContentFromOverride(DocumentElement fromElement) { }