private static void AddOrOverwriteWordCountFeature(ZoneTree tree) { var leafWalker = new BreadthFirstWalkerFactory().CreateLeafWalker(); tree.Accept(new FeatureExtractionVisitor <Zone>(TOKENS_FEATURE_NAME, new Tokens(_naturalLanguageProcessor)), leafWalker); tree.Accept(new FeatureExtractionVisitor <Zone>(WORD_COUNT_FEATURE_NAME, new WordCount(TOKENS_FEATURE_NAME)), leafWalker); }
private void CreateOrUpdateZoneOutlineHighlights(ZoneTree zoneTree) { var style = _styleFactory.CreateZoneOutlineStyle(); var highlights = zoneTree.LeafNodes.Select(z => new HighlightSpec(style, z.BoundingBox)); this.AddOrUpdateHighlights(ZONE_OUTLINE_TYPE, highlights); }
/// <summary> /// Runs the post processing steps /// </summary> /// <param name="tree">The zone tree</param> private void RunPostProcessingSteps(ZoneTree tree) { foreach (var step in this.PostProcessingSteps) { tree.Accept(step); } }
/// <summary> /// Clears the tree data /// </summary> private void ClearTreeData() { _zoneTree = null; _columnTree = null; _rootZoneNode = null; _rootDomNode = null; _rootColumnNode = null; }
public void ShowHighlights(ZoneTree tree, IEnumerable <HighlightSpec> highlightSpecs) { this.ClearHighlights(); foreach (var spec in highlightSpecs) { var highlight = new WpfHighlight(spec); _highlightCanvas.Children.Add(highlight); } }
private static Tuple <double, double, double> Evaluate(ZoneTree tree, string baselineLabel) { int predictedWordCount = PredictedWordCount(tree); int correctlyPredictedWordCount = CorrectlyPredictedWordCount(tree, baselineLabel); int baselineWordCount = BaselineWordCount(tree, baselineLabel); var precision = Precision(correctlyPredictedWordCount, predictedWordCount); var recall = Recall(correctlyPredictedWordCount, baselineWordCount); var fScore = FScore(precision, recall); return(new Tuple <double, double, double>(precision, recall, fScore)); }
/// <summary> /// Sets the zone tree /// </summary> /// <param name="zoneTree">The zone tree</param> private void SetZoneTree(ZoneTree zoneTree) { this.ClearTreeData(); if (zoneTree != null) { _zoneTree = zoneTree; _columnTree = _appServices.CreateColumnTree(zoneTree); _rootDomNode = new ElementTreeNode(_zoneTree.Document.Body); _rootZoneNode = new ZoneTreeNode(_zoneTree.Root); _rootColumnNode = new ColumnTreeNode(_columnTree.Root); } }
public void SaveZoneTree(string saveFilePath, ZoneTree tree) { var sOutput = _documentSerializer.Serialize(tree.Document); string zoneTreeXml = _zoneTreeSerializer.Serialize(tree); var paths = this.ConstructFilePaths(saveFilePath); File.WriteAllText(paths.DocumentHtmlPath, sOutput.DomHtml); File.WriteAllText(paths.DocumentTextPath, sOutput.DomText); File.WriteAllText(paths.DocumentXmlPath, sOutput.DomTreeXml); File.WriteAllText(paths.ZoneTreeXmlPath, zoneTreeXml); }
private void LoadTreeStore() { //dont select tree, get the tree node from current zone content //assuming the parent is a zone type for now ZoneTree parentTree = (ZoneTree)gameDataObject.treeStore.getCurrentTree(); ZoneTreeNode parentTreeNode = (ZoneTreeNode)parentTree.getNode(parentTree.currentIndex); long storeLink = parentTreeNode.content.linkIndex; parentTreeLink = gameDataObject.treeStore.currentTreeIndex; gameDataObject.treeStore.SelectTree(storeLink); storeTree = (StoreTree)gameDataObject.treeStore.getCurrentTree(); }
/// <summary> /// Serializes a zone tree /// </summary> /// <param name="rootDirectory">The root directory</param> /// <param name="pmid">The pmid</param> /// <param name="zoneTree">The zone tree</param> /// <param name="url">The URL</param> internal void SerializeZoneTree(string rootDirectory, string pmid, ZoneTree zoneTree, string url) { var output = _htmlDocumentSerializer.Serialize(zoneTree.Document); string zoneTreeXml = _zoneTreeSerializer.Serialize(zoneTree); var paths = this.ConstructFilePaths(rootDirectory, pmid); File.WriteAllText(paths.DocumentHtmlPath, output.DomHtml); File.WriteAllText(paths.DocumentTextPath, output.DomText); File.WriteAllText(paths.DocumentXmlPath, output.DomTreeXml); File.WriteAllText(paths.ZoneTreeXmlPath, zoneTreeXml); File.WriteAllText(paths.UrlPath, url); }
/// <summary> /// Builds a column tree /// </summary> /// <param name="zoneTree">The zone tree</param> /// <param name="collapseBranches">Whether to collapse branches and merge children</param> /// <returns> /// The created column tree /// </returns> public ColumnTree Build(ZoneTree zoneTree, bool collapseBranches) { _count = 0; var rootNode = this.CreateColumn(null, zoneTree.Root); this.Build(rootNode); var tree = new ColumnTree(rootNode, zoneTree); if (collapseBranches) { tree.Accept(new CollapseBranches(_tolerance), new BreadthFirstWalkerFactory().CreateReversed()); } return(tree); }
public ZoneTree LoadZoneTree(string openFilepath) { ZoneTree tree = null; var paths = this.ConstructFilePaths(openFilepath); if (File.Exists(paths.ZoneTreeXmlPath)) { var documentHtml = File.ReadAllText(paths.DocumentHtmlPath); var documentText = File.ReadAllText(paths.DocumentTextPath); var documentXml = File.ReadAllText(paths.DocumentXmlPath); var zoneTreeXml = File.ReadAllText(paths.ZoneTreeXmlPath); tree = _zoneTreeSerializer.Deserialize(documentHtml, documentText, documentXml, zoneTreeXml); } return(tree); }
private void SetInitialLabels(ZoneTree zoneTree) { var labelList = _config.SEED_LABELS.ToList(); var zoneTreeLabels = zoneTree.LeafNodes.SelectMany(z => z.Classifications).Distinct(); foreach (var zoneTreeLabel in zoneTreeLabels) { if (!labelList.Contains(zoneTreeLabel)) { labelList.Add(zoneTreeLabel); } } var labels = new ObservableCollection <LabelInfo>(labelList.Select(l => new LabelInfo(l, false))); this.Labels = labels; }
//DEPRECATED public static ITree getTreeFromFile(string path, TreeType treeType, GlobalFlags gf) { ITree t = null; List <ITreeNode> treeNodeList = null; switch (treeType) { case TreeType.World: WorldTree worldTree = new WorldTree(gf, treeType); treeNodeList = getTreeNodeListFromFile(path, treeType); worldTree.treeNodeDictionary = getWorldTreeNodeFromList(treeNodeList); worldTree.currentIndex = treeNodeList[0].index; t = worldTree; break; case TreeType.Zone: ZoneTree zoneTree = new ZoneTree(gf, treeType); treeNodeList = getTreeNodeListFromFile(path, treeType); zoneTree.treeNodeDictionary = getZoneTreeNodeFromList(treeNodeList); zoneTree.currentIndex = treeNodeList[0].index; t = zoneTree; break; case TreeType.Dialog: DialogTree dialogTree = new DialogTree(gf, treeType); treeNodeList = getTreeNodeListFromFile(path, treeType); dialogTree.treeNodeDictionary = getDialogTreeNodeFromList(treeNodeList); dialogTree.currentIndex = treeNodeList[0].index; t = dialogTree; break; case TreeType.Quest: QuestTree questTree = new QuestTree(gf, treeType); treeNodeList = getTreeNodeListFromFile(path, treeType); questTree.treeNodeDictionary = getQuestTreeNodeFromList(treeNodeList); questTree.currentIndex = treeNodeList[0].index; t = questTree; break; default: break; } return(t); }
public static ITree getTreeFromFile(string path,TreeType treeType, GlobalFlags gf) { ITree t = null; List<ITreeNode> treeNodeList = null; switch (treeType) { case TreeType.World: WorldTree worldTree = new WorldTree(gf, treeType); treeNodeList = getTreeNodeListFromFile(path,treeType); worldTree.treeNodeDictionary = getWorldTreeNodeFromList(treeNodeList); worldTree.currentIndex = treeNodeList[0].index; t = worldTree; break; case TreeType.Zone: ZoneTree zoneTree = new ZoneTree(gf, treeType); treeNodeList = getTreeNodeListFromFile(path,treeType); zoneTree.treeNodeDictionary = getZoneTreeNodeFromList(treeNodeList); zoneTree.currentIndex = treeNodeList[0].index; t = zoneTree; break; case TreeType.Dialog: DialogTree dialogTree = new DialogTree(gf, treeType); treeNodeList = getTreeNodeListFromFile(path,treeType); dialogTree.treeNodeDictionary = getDialogTreeNodeFromList(treeNodeList); dialogTree.currentIndex = treeNodeList[0].index; t = dialogTree; break; case TreeType.Quest: QuestTree questTree = new QuestTree(gf, treeType); treeNodeList = getTreeNodeListFromFile(path,treeType); questTree.treeNodeDictionary = getQuestTreeNodeFromList(treeNodeList); questTree.currentIndex = treeNodeList[0].index; t = questTree; break; default: break; } return t; }
public void ShowHighlights(ZoneTree tree, IEnumerable <HighlightSpec> highlightSpecs) { var toRemove = _highlights.Except(highlightSpecs).ToArray(); foreach (HtmlHighlight highlight in toRemove) { highlight.Remove(); _highlights.Remove(highlight); } var toAdd = highlightSpecs.Except(_highlights); foreach (var spec in toAdd) { var highlight = HtmlHighlight.Create(_msDoc, spec); _highlights.Add(highlight); } var verticalScrollAreas = this.GetVerticalScrollArea(tree); this.NotifyHighlightsUpdated(verticalScrollAreas); }
public void LoadBattle(int battleIndex) { int treeIndex = 1; int nodeIndex = 1; //select the parent tree link: switch (battleIndex) { case 1: gameDataObject.playerGameCharacter = getGameCharacterFromID(80012); gameDataObject.addCharacter(80011); nodeIndex = 3; break; case 2: gameDataObject.playerGameCharacter = getGameCharacterFromID(80012); gameDataObject.addCharacter(80011); treeIndex = 3; nodeIndex = 3; break; case 3: gameDataObject.playerGameCharacter = getGameCharacterFromID(80012); gameDataObject.addCharacter(80011); treeIndex = 19; nodeIndex = 2; break; default: break; } gameDataObject.treeStore.SelectTree(treeIndex); ZoneTree curTree = (ZoneTree)gameDataObject.treeStore.getTree(gameDataObject.treeStore.currentTreeIndex); curTree.SelectNode(nodeIndex); SceneManager.LoadScene((int)UnitySceneIndex.Battle); }
/// <summary> /// Builds the zone tree /// </summary> /// <param name="classifiedDoc">The classified html document</param> /// <returns> /// a zone tree /// </returns> public ZoneTree Build(SerializableDocument classifiedDoc) { try { _currentId = 0; var bodyZone = new Zone(_currentId, null); var bodyElement = (SerializableElement)classifiedDoc.Body; bodyZone.AddElement(bodyElement); this.Build(bodyZone); this.CropZoneText(bodyZone, classifiedDoc.Text); this.SetDisplayOrder(bodyZone); var tree = new ZoneTree(bodyZone, classifiedDoc); this.RunPostProcessingSteps(tree); return(tree); } catch (Exception ex) { throw new Exception("Error building zone tree", ex); } }
private Rectangle GetVerticalScrollArea(ZoneTree tree) { int width; int height; if (tree == null) { var body = (IHTMLElement2)_msDoc.body; width = body.clientWidth; height = body.clientHeight; } else { var window = _msDoc.parentWindow; width = (int)((IExpando)window).GetProperty("innerWidth", BindingFlags.Default).GetValue(window); width -= SCROLL_BAR_WIDTH; height = tree.Document.All.Max(e => e.BoundingBox.Bottom); } var bb = new Rectangle(0, 0, width, height); return(bb); }
private static int BaselineWordCount(ZoneTree tree, string baselineLabel) { int count = WordCount(tree, baselineLabel); return(count); }
public static ITree getTreeFromString(string data, TreeType treeType, GlobalFlags gf) { ITree t = null; List<ITreeNode> treeNodeList = null; switch (treeType) { case TreeType.World: WorldTree worldTree = new WorldTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); worldTree.treeNodeDictionary = getWorldTreeNodeFromList(treeNodeList); worldTree.currentIndex = treeNodeList[0].index; t = worldTree; break; case TreeType.Zone: ZoneTree zoneTree = new ZoneTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); zoneTree.treeNodeDictionary = getZoneTreeNodeFromList(treeNodeList); zoneTree.currentIndex = treeNodeList[0].index; t = zoneTree; break; case TreeType.Dialog: DialogTree dialogTree = new DialogTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); dialogTree.treeNodeDictionary = getDialogTreeNodeFromList(treeNodeList); dialogTree.currentIndex = treeNodeList[0].index; t = dialogTree; break; case TreeType.Quest: QuestTree questTree = new QuestTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); questTree.treeNodeDictionary = getQuestTreeNodeFromList(treeNodeList); questTree.currentIndex = treeNodeList[0].index; t = questTree; break; case TreeType.Battle: BattleTree battleTree = new BattleTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); battleTree.treeNodeDictionary = getBattleTreeNodeFromList(treeNodeList); battleTree.currentIndex = treeNodeList[0].index; t = battleTree; break; case TreeType.Info: InfoTree infoTree = new InfoTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); infoTree.treeNodeDictionary = getInfoTreeNodeFromList(treeNodeList); infoTree.currentIndex = treeNodeList[0].index; t = infoTree; break; default: break; } return t; }
public Bitmap TakeScreenshot(ZoneTree tree) { Bitmap screenshot = null; try { var html = (IHTMLElement2)_msDoc.body.parentElement; var htmlStyle = html.runtimeStyle; string overflowX = html.currentStyle.getAttribute(Css.Properties.OVERFLOWX)?.ToString(); htmlStyle.setAttribute(Css.Properties.OVERFLOWX, Css.Values.OVERFLOW_HIDDEN); var verticalScrollArea = this.GetVerticalScrollArea(tree); var viewObject = (IViewObject)_msDoc; var window = _msDoc.parentWindow; int viewPortWidth = verticalScrollArea.Width; int viewPortHeight = (int)((IExpando)window).GetProperty("innerHeight", BindingFlags.Default).GetValue(window); int scrollHeight = verticalScrollArea.Height; int numScrolls = (int)Math.Ceiling((double)scrollHeight / viewPortHeight); screenshot = new Bitmap(viewPortWidth, scrollHeight); using (var screenshotGraphics = Graphics.FromImage(screenshot)) { screenshotGraphics.Clear(Color.Red); for (int i = 0; i < numScrolls; i++) { if (i == 1) { new HidePositionFixed(OPACITY_CUST_ATTR_NAME).Apply(_msDoc); } bool last = (i == (numScrolls - 1)); int scrollTop; if (last) { scrollTop = (scrollHeight - viewPortHeight); } else { scrollTop = (i * viewPortHeight); } window.scroll(0, scrollTop); using (var fragment = new Bitmap(viewPortWidth, viewPortHeight)) using (var fragmentGraphics = Graphics.FromImage(fragment)) { var fragmentHdc = fragmentGraphics.GetHdc(); try { viewObject.Draw(1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0, fragmentHdc, Rectangle.Empty, (IntPtr)0, (IntPtr)0, 0); } finally { fragmentGraphics.ReleaseHdc(fragmentHdc); } screenshotGraphics.DrawImage(fragment, 0, scrollTop); } } } new ShowPositionFixed(OPACITY_CUST_ATTR_NAME).Apply(_msDoc); if (overflowX != null) { htmlStyle.setAttribute(Css.Properties.OVERFLOWX, overflowX); } else { htmlStyle.setAttribute(Css.Properties.OVERFLOWX, Css.Values.OVERFLOW_VISIBLE); } window.scroll(0, 0); } catch { screenshot?.Dispose(); screenshot = null; } return(screenshot); }
/// <summary> /// Creates a column tree /// </summary> /// <param name="zoneTree">The zone tree</param> /// <returns></returns> internal ColumnTree CreateColumnTree(ZoneTree zoneTree) { bool collapseBranches = true; return(_columnTreeBuilder.Build(zoneTree, collapseBranches)); }
/// <summary> /// Labels the article content using the article semantic tag algorithm /// </summary> /// <param name="zoneTree">The zone tree</param> internal void ArticleTagArticleContentLabeling(ZoneTree zoneTree) { _articleTagArticleContentLabeler.Execute(zoneTree); }
/// <summary> /// Labels the article content using the main semantic tag algorithm /// </summary> /// <param name="zoneTree">The zone tree</param> internal void MainTagArticleContentLabeling(ZoneTree zoneTree) { _mainTagArticleContentLabeler.Execute(zoneTree); }
private void CreateOrUpdateZoneLabelHighlights(IEnumerable <LabelInfo> selecectedLabels, ZoneTree zoneTree) { var highlights = new List <HighlightSpec>(); foreach (var labelInfo in selecectedLabels) { string label = labelInfo.Label; var style = _styleFactory.CreateLabeledZoneStyle(labelInfo.ColorName); var labelHighlights = zoneTree.LeafNodes.Where(z => z.HasClassification(label)).Select(z => new HighlightSpec(style, z.BoundingBox)); highlights.AddRange(labelHighlights); } this.AddOrUpdateHighlights(LABELED_ZONE_TYPE, highlights); }
private void loadTree() { zoneTree = (ZoneTree)gameDataObject.treeStore.getCurrentTree(); }
public Bitmap TakeScreenshot(ZoneTree tree) { return((Bitmap)Image.FromFile(_imagePath)); }
private static int PredictedWordCount(ZoneTree tree) { int count = WordCount(tree, ARTICLE_CONTENT_LABEL); return(count); }
private static int CorrectlyPredictedWordCount(ZoneTree tree, string baselineLabel) { int count = tree.LeafNodes.Where(l => HasLabel(l, baselineLabel) && HasLabel(l, ARTICLE_CONTENT_LABEL)).Sum(l => l.GetFeature(WORD_COUNT_FEATURE_NAME).AsInt()); return(count); }
public static ITree getTreeFromString(string data, TreeType treeType, GlobalFlags gf) { ITree t = null; List <ITreeNode> treeNodeList = null; switch (treeType) { case TreeType.World: WorldTree worldTree = new WorldTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); worldTree.treeNodeDictionary = getWorldTreeNodeFromList(treeNodeList); worldTree.currentIndex = treeNodeList[0].index; t = worldTree; break; case TreeType.Zone: ZoneTree zoneTree = new ZoneTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); zoneTree.treeNodeDictionary = getZoneTreeNodeFromList(treeNodeList); zoneTree.currentIndex = treeNodeList[0].index; t = zoneTree; break; case TreeType.Dialog: DialogTree dialogTree = new DialogTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); dialogTree.treeNodeDictionary = getDialogTreeNodeFromList(treeNodeList); dialogTree.currentIndex = treeNodeList[0].index; t = dialogTree; break; case TreeType.Quest: QuestTree questTree = new QuestTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); questTree.treeNodeDictionary = getQuestTreeNodeFromList(treeNodeList); questTree.currentIndex = treeNodeList[0].index; t = questTree; break; case TreeType.Battle: BattleTree battleTree = new BattleTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); battleTree.treeNodeDictionary = getBattleTreeNodeFromList(treeNodeList); battleTree.currentIndex = treeNodeList[0].index; t = battleTree; break; case TreeType.Info: InfoTree infoTree = new InfoTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); infoTree.treeNodeDictionary = getInfoTreeNodeFromList(treeNodeList); infoTree.currentIndex = treeNodeList[0].index; t = infoTree; break; case TreeType.Store: StoreTree storeTree = new StoreTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); storeTree.treeNodeDictionary = getStoreTreeNodeFromList(treeNodeList); storeTree.currentIndex = treeNodeList[0].index; t = storeTree; break; case TreeType.Cutscene: CutsceneTree cutsceneTree = new CutsceneTree(gf, treeType); treeNodeList = getTreeNodeListFromString(data, treeType); cutsceneTree.treeNodeDictionary = getCutsceneTreeNodeFromList(treeNodeList); cutsceneTree.currentIndex = treeNodeList[0].index; t = cutsceneTree; break; default: break; } return(t); }
private static int WordCount(ZoneTree tree, string label) { int count = tree.LeafNodes.Where(l => HasLabel(l, label)).Sum(l => l.GetFeature(WORD_COUNT_FEATURE_NAME).AsInt()); return(count); }