コード例 #1
0
        /// <summary>
        /// Returns depth of nesting level of the given type, along given node to the document root.
        /// </summary>
        /// <param name="currentNode"></param>
        /// <param name="feature"></param>
        /// <returns></returns>
        public int GetNestedDepth(Feature currentNode, String feature)
        {
            //If a parent is repeated and most higher feature(closer to root) is parent return 1
            //if parent equals current return  real depth

            Feature tmpNode = currentNode;

            while (tmpNode.Parent != null)
            {
                if (tmpNode.Name.Equals(feature)) break;

                int parentRepeats = GetNestedCount(tmpNode, tmpNode.Name);

                String rootFeature = GetRootFeature(tmpNode, feature, tmpNode.Name);

                if (parentRepeats > 1 && rootFeature.Equals(tmpNode.Name))
                {
                    return 0;
                }

                tmpNode = tmpNode.Parent;

            }
            return GetNestedCount(currentNode, feature);
        }
コード例 #2
0
        private void AddStyle(Feature feature)
        {
            IEnumerable<StyleInfo> stylesConstraints = randomizer.GetRandomStyleSubset(feature.Name);

            float styleAddingProb = Config.Default.StyleAddProb;

            float randomVal = (float) randomNumber.NextDouble();

            //Only add styles to fraction of features
            if (randomVal < styleAddingProb)
            {
                List<Style> possibleStyles = new List<Style>();

                foreach (var item in stylesConstraints)
                {
                    possibleStyles.Add(StyleFactory.CreateStyle(item, defaults));
                }

                foreach (var style in possibleStyles)
                {
                    feature.AddStyle(style);
                }
            }

            foreach (var subFeature in feature.GetChildFeatures())
            {
                AddStyle(subFeature);
            }
        }
コード例 #3
0
        private void ProcessLeaf(Feature node)
        {
            if (node.SubFeaturesCompleted) return;

            IEnumerable<String> randomFeatures = randomGen.GetRandomFeatureList(node.Name);

            foreach (var randomFeature in randomFeatures)
            {
                //Limiting depth of recursive features
                if (docTree.GetNestedDepth(node, randomFeature) >= configuration.GetMaxNestingDepth(randomFeature))
                {
                    continue;
                }

                int childCount = GetChildCount(node.Name, randomFeature);

                for (int i = 0; i < childCount; i++)
                {
                    if (node.GetSubFeatureCount(randomFeature) < childCount)
                    {
                        node.AddSubElement(FeatureFactory.CreateFeature(randomFeature, DataProvider));
                    }
                }
            }

            node.ShuffleChilds();

            node.SubFeaturesCompleted = true;
        }
コード例 #4
0
        public static Feature CreateFeature(String featureName, IDataProvider dataProvider)
        {
            Feature tmp = new Feature();
            tmp.Name = featureName;

            tmp.Value = dataProvider.GetSampleData(featureName);
            return tmp;
        }
コード例 #5
0
        private void AddToXml(Feature feature, XElement element)
        {
            if (feature.Value != null) {
                element.Value = feature.Value;
            }

            foreach (var style in feature.GetStyles())
            {
                XAttribute tmp = new XAttribute(style.Name, style.Value);
                element.Add(tmp);
            }

            IEnumerable<Feature> subElements = feature.GetChildFeatures();

            foreach (var subElement in subElements)
            {
                XElement tmp = new XElement(subElement.Name);
                element.Add(tmp);
                AddToXml(subElement, tmp);
            }
        }
コード例 #6
0
        public String GetNodePath(Feature node)
        {
            List<String> featureName = new List<String>();
            Feature parent = node;

            while ( parent != null)
            {
                featureName.Add(parent.Name);
                parent = parent.Parent;
            }

            StringBuilder path = new StringBuilder();

            for (int i = featureName.Count()-1 ; i >= 0; i--)
            {
                path.Append("/");
                path.Append(featureName[i]);
            }

            return path.ToString();
        }
コード例 #7
0
        private void AddSpecificStyle(Feature feature)
        {
            String path = document.GetNodePath(feature);
            IEnumerable<StyleInfo> styleConstraints = configFacade.GetStylesPartial(path);

            List<Style> specificStyles = new List<Style>();

            foreach (var item in styleConstraints)
            {
                specificStyles.Add(StyleFactory.CreateStyle(item, defaults));
            }

            foreach (var style in specificStyles)
            {
                feature.AddStyle(style, true); //Should we check style compatibility here
            }

            foreach (var subFeature in feature.GetChildFeatures())
            {
                AddSpecificStyle(subFeature);
            }
        }
コード例 #8
0
 private void CalculateLeafNodes(Feature node, List<Feature> leaves)
 {
     if (IsLeaf(node))
     {
         leaves.Add(node);
         return;
     }
     else {
         foreach (var childNode in node.GetChildFeatures())
         {
             CalculateLeafNodes(childNode, leaves);
         }
     }
 }
コード例 #9
0
 private bool IsLeaf(Feature node)
 {
     if (node.GetSubFeatureCount() == 0) {
         return true;
     }
     return false;
 }
コード例 #10
0
        private String GetRootFeature(Feature currentNode, String feature1, String feature2)
        {
            int feature1Depth = GetDepthToFirst(currentNode, feature1);
            int feature2Depth = GetDepthToFirst(currentNode, feature2);

            return feature1Depth < feature2Depth ? feature1 : feature2;
        }
コード例 #11
0
        /// <summary>
        /// Returns number of repititions for the given feature along the current node to the root
        /// </summary>
        /// <param name="currentNode"></param>
        /// <param name="feature"></param>
        /// <returns></returns>
        private int GetNestedCount(Feature currentNode, String feature)
        {
            Feature immidiateParent = currentNode;
            int depthCount = 0;

            while (immidiateParent != null)
            {
                if (immidiateParent.Name.Equals(feature)) depthCount++;
                immidiateParent = immidiateParent.Parent;
            }

            return depthCount;
        }
コード例 #12
0
        /// <summary>
        /// returns the depth to the first occurance of a given feature along root to the current node
        /// </summary>
        /// <param name="currentNode"></param>
        /// <param name="feature"></param>
        /// <returns></returns>
        private int GetDepthToFirst(Feature currentNode, String feature)
        {
            Feature immidiateParent = currentNode.Parent;

            List<String> path = new List<String>();
            path.Add(currentNode.Name);

            while (immidiateParent != null)
            {
                path.Add(immidiateParent.Name);
                immidiateParent = immidiateParent.Parent;
            }

            return path.Count - path.LastIndexOf(feature);
        }
コード例 #13
0
 public DocumentTree()
 {
     Root = new Feature();
     Root.Name = "document"; //TODO: provide external interface
 }
コード例 #14
0
 public void AddSubElement(Feature subElement)
 {
     subElements.Add(subElement);
     subElement.Parent = this;
 }