Пример #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (jury1DSetup1.Enabled)
            {
                ProfileTree t = ProfileAutomatic.AnalyseProfileFile(profileFile, SIMDIST.SIMILARITY);

                if (t != null)
                {
                    string profileName = "automatic_similarity.profile";
                    t.SaveProfiles(profileName);
                    jury1DSetup1.profileName = profileName;
                }
                else
                {
                    MessageBox.Show("Could not create automatic profile");
                }
            }
            if (distanceControl1.Enabled)
            {
                if (distanceControl1.distDef == DistanceMeasures.HAMMING)
                {
                    ProfileTree t           = ProfileAutomatic.AnalyseProfileFile(profileFile, SIMDIST.DISTANCE);
                    string      profileName = "automatic_distance.profile";
                    t.SaveProfiles(profileName);
                    distanceControl1.profileName = profileName;
                }
                if (distanceControl1.reference)
                {
                    ProfileTree t           = ProfileAutomatic.AnalyseProfileFile(profileFile, SIMDIST.SIMILARITY);
                    string      profileName = "automatic_similarity.profile";
                    t.SaveProfiles(profileName);
                    distanceControl1.referenceProfile = profileName;
                }
            }
        }
Пример #2
0
        private JToken ToJson(ProfileTree tree, string[] prefix)
        {
            string[] newPrefix = prefix
                                 .Concat(new[] { tree.NameString })
                                 .ToArray();

            switch (tree)
            {
            case ProfileTreeNode node:
                return(hiddenKeys.Contains(newPrefix.ToQualifiedName())
                        ? (JToken) new JArray(node.Children
                                              .Select(child =>
                                                      ToJson(
                                                          child,
                                                          newPrefix)).ToArray())
                        : new JObject(node.Children
                                      .Select(child =>
                                              new JProperty(
                                                  child.NameString,
                                                  ToJson(
                                                      child,
                                                      newPrefix)))
                                      .ToArray()));

            case ProfileTreeLeaf leaf:
                return(ToJsonValue(leaf.Value, newPrefix));

            default:
                throw new NotSupportedException();
            }
        }
Пример #3
0
        private string LabelActiveProfiles(string fileName)
        {
            string      outStr = "";
            ProfileTree tree   = new ProfileTree();

            try
            {
                tree.LoadProfiles(fileName);
            }
            catch (Exception)
            {
                label2.Text = "";
                return(null);
            }
            inputMode = tree.GetModes();
            List <profileNode> active = tree.GetActiveProfiles();

            outStr = "Active profiles: ";
            if (active != null)
            {
                for (int i = 0; i < active.Count; i++)
                {
                    outStr += active[i].profName;
                    if (i < active.Count - 1)
                    {
                        outStr += ", ";
                    }
                }
            }

            return(outStr);
        }
Пример #4
0
        public ProfileForm(string fileName, string alignFile, filterOPT filter)
        {
            InitializeComponent();
            if (fileName == null || fileName.Length == 0)
            {
                this.Text = "Profile not defined";
            }
            else
            {
                this.Text     = fileName;
                this.fileName = fileName;
            }

            this.filter = filter;
            //profilesView.DrawMode = TreeViewDrawMode.OwnerDrawText;

            treeProfiles = new ProfileTree();
            if (fileName != null && fileName.Length > 0)
            {
                if (File.Exists(fileName))
                {
                    treeProfiles.LoadProfiles(fileName);
                }
            }

            ShowTree();
            //profilesView.
        }
Пример #5
0
        public async Task Write(ProfileTree tree, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var errors = tree
                         .GetAllChildren()
                         .Select(tuple => tuple.tree)
                         .OfType <ProfileTreeError>()
                         .OrderBy(pair => pair.SourceMark)
                         .ToList();

            if (errors.Count > 0)
            {
                foreach (var error in errors)
                {
                    logger.Error(new
                    {
                        message  = "Error reading input",
                        error    = error.Error,
                        fileName = error.SourceMark.FileName,
                        line     = error.SourceMark.LineNumber
                    });
                }

                throw new ApplicationException();
            }

            using (var stream = outputStreamFactory())
                await DoWrite(tree, stream, cancellationToken);
        }
Пример #6
0
        private void button3_Click(object sender, EventArgs e)
        {
            ProfileTree t           = ProfileAutomatic.AnalyseProfileFile(profileFile, SIMDIST.SIMILARITY);
            string      profileName = "automatic_similarity.profile";

            t.SaveProfiles(profileName);
            jury1DSetup1.profileName = profileName;
        }
Пример #7
0
 protected override async Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken)
 {
     using (var writer = new StreamWriter(stream))
         using (var jsonWriter = new JsonTextWriter(writer)
         {
             Formatting = Formatting.Indented
         })
             await ToJson(tree, new string[0])
             .WriteToAsync(jsonWriter);
 }
Пример #8
0
 protected override async Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken)
 {
     using (var writer = new StreamWriter(stream))
         foreach (var line in tree
                  .GetLeafs()
                  .OrderBy(pair => pair.leaf.SourceMark)
                  .SelectMany(pair => FormatEntry(pair.prefix, pair.leaf)))
         {
             await writer.WriteLineAsync(line.ToCharArray(), cancellationToken);
         }
 }
        private static bool IsArray(ProfileTree tree)
        {
            if (!(tree is ProfileTreeNode node))
            {
                return(false);
            }

            var cnt = node.Children.Count(child => child.Name.Tokens.Count == 1 && child.Name.Tokens[0] is TextNameToken token && token.Text.All(char.IsDigit));

            return(cnt > 0 && cnt == node.Children
                   .Count(child => !(child.Name.Tokens.Count == 1 && child.Name.Tokens[0] is SubstituteNameToken)));
        }
Пример #10
0
        protected override async Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken)
        {
            var serializer = new SerializerBuilder()
                             .WithEventEmitter(nextEmitter => new QuoteStringEventEmitter(nextEmitter))
                             .Build();

            using (var writer = new StreamWriter(stream))
                await writer.WriteAsync(
                    serializer
                    .Serialize(ToObject(tree, new string[0]))
                    .ToCharArray(),
                    cancellationToken);
        }
Пример #11
0
        public void Prepare(List<KeyValuePair<string,string>> profilesStr,string profName,string profFile)
        {
            r = new ProfileTree();
            r.LoadProfiles(profFile);            
            
            foreach(var item in profilesStr)
            {
                List<string> aux = new List<string>(item.Value.Length);
                for (int i = 0; i < item.Value.Length; i++)
                    aux.Add(item.Value[i].ToString());

               r.AddItemsCombineStates(item.Key,aux);
                                
            }
        }
Пример #12
0
        private void MakeViewCopy(ProfileTree tr, TreeNode node)
        {
            foreach (TreeNode item in node.Nodes)
            {
                string Path = item.FullPath;
                Path = PathRemoveRoot(Path);
                Path = ParentPath(Path);
                tr.AdddNode(Path, new profileNode((profileNode)item.Tag));

                if (item.Nodes.Count > 0)
                {
                    MakeViewCopy(tr, item);
                }
            }
        }
Пример #13
0
        private void GetNodes(TreeNode node, ProfileTree tree)
        {
            profileNode nodeP;
            string      parentPath = node.FullPath;
            Regex       reg        = new Regex("^Profiles");

            parentPath = reg.Replace(parentPath, "");
            foreach (TreeNode item in node.Nodes)
            {
                string Path = item.FullPath;
                Path  = reg.Replace(Path, "");
                nodeP = treeProfiles.FindNode(Path);
                tree.AdddNode(parentPath, new profileNode(nodeP));
                if (item.Nodes != null)
                {
                    GetNodes(item, tree);
                }
            }
        }
Пример #14
0
        protected override async Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken)
        {
            var xmlNamespaces = (from pair in tree.GetLeafs()
                                 where pair.leaf.NameString.StartsWith("xmlns:")
                                 select new { Key = pair.leaf.NameString.Substring(6), pair.leaf.Value })
                                .ToDictionary(x => x.Key, x => XNamespace.Get(x.Value));

            using (var writer = new StreamWriter(stream))
                using (var xmlWriter = XmlWriter.Create(writer, new XmlWriterSettings
                {
                    Async = true,
                    Indent = (xmlOptions & XmlOptions.NoIndent) == XmlOptions.None,
                    NewLineOnAttributes = (xmlOptions & XmlOptions.NewLineOnAttributes) == XmlOptions.NewLineOnAttributes
                }))
                    await ApplyOutputPrefix(
                        (XElement)ToXml(tree, new string[0], "", xmlNamespaces)
                        .Single()
                        .node)
                    .WriteToAsync(xmlWriter, cancellationToken);
        }
Пример #15
0
        private void button5_Click(object sender, EventArgs e)
        {
            DialogResult res = openFileDialog1.ShowDialog();

            if (res == DialogResult.OK)
            {
                localNode.profName = textBox1.Text;
                ProfileTree t = ProfileAutomatic.AnalyseProfileFile(openFileDialog1.FileName, SIMDIST.SIMILARITY);

                if (t.masterNode.ContainsKey(localNode.profName))
                {
                    dataGridView1.Rows.Clear();
                    foreach (var item in t.masterNode[localNode.profName].states.Keys)
                    {
                        dataGridView1.Rows.Add(1);
                        dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[0].Value = item;
                        dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[1].Value = item;
                    }
                }
            }
        }
Пример #16
0
        public ProfileForm(string fileName,string alignFile,filterOPT filter)
        {
            InitializeComponent();
            if (fileName == null || fileName.Length == 0)
                this.Text = "Profile not defined";
            else
            {
                this.Text = fileName;
                this.fileName = fileName;
            }

            this.filter = filter;
            //profilesView.DrawMode = TreeViewDrawMode.OwnerDrawText;
            
            treeProfiles = new ProfileTree();
            if(fileName!=null && fileName.Length>0)
                if(File.Exists(fileName))
                    treeProfiles.LoadProfiles(fileName);
           
            ShowTree();
            //profilesView.
        }
Пример #17
0
        public ProfileForm(string fileName, string alignFile, filterOPT filter)
        {
            InitializeComponent();
            if (fileName == null || fileName.Length == 0)
            {
                this.Text = "Profile not defined";
            }
            else
            {
                this.Text     = fileName;
                this.fileName = fileName;
            }

            this.filter = filter;
            //profilesView.DrawMode = TreeViewDrawMode.OwnerDrawText;

            treeProfiles = new ProfileTree();
            if (fileName != null && fileName.Length > 0)
            {
                if (File.Exists(fileName))
                {
                    treeProfiles.LoadProfiles(fileName);
                    if (treeProfiles.combine == profileCombination.JOIN_STATES)
                    {
                        toolStripButton1.Enabled = false;
                        toolStripButton4.Enabled = true;
                    }
                    else
                    {
                        toolStripButton1.Enabled = true;
                        toolStripButton4.Enabled = false;
                    }
                }
            }

            ShowTree();
            //profilesView.
        }
Пример #18
0
        private object ToObject(ProfileTree tree, string[] prefix)
        {
            string[] newPrefix = prefix
                                 .Concat(new[] { tree.NameString })
                                 .ToArray();

            switch (tree)
            {
            case ProfileTreeNode node:
                return(hiddenKeys.Contains(newPrefix.ToQualifiedName())
                        ? (object)node.Children.Select(
                           child => ToObject(child, newPrefix)).ToArray()
                        : node.Children.ToDictionary(
                           child => child.NameString,
                           child => ToObject(child, newPrefix)));

            case ProfileTreeLeaf leaf:
                return(ToObjectValue(leaf.Value, newPrefix));

            default:
                throw new NotSupportedException();
            }
        }
Пример #19
0
        protected override async Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken)
        {
            using (var memoryStream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                {
                    var parser = new IniStreamParser();
                    var data   = new IniData();

                    foreach (var(prefix, leaf) in tree.GetLeafs())
                    {
                        var names = prefix.Parts
                                    .Select(part => part.Tokens.Cast <TextNameToken>().Single().Text)
                                    .Skip(1);

                        if (outputPrefix != null)
                        {
                            names = outputPrefix.Concat(names);
                        }

                        if (delimiter == ".")
                        {
                            names = names.Select(name => name.Replace(".", "\\."));
                        }

                        data[names.First()][string.Join(delimiter, names.Skip(1))] = leaf.Value;
                    }

                    parser.WriteData(writer, data);

                    await writer.FlushAsync();

                    memoryStream.Seek(0, SeekOrigin.Begin);

                    await memoryStream.CopyToAsync(stream);
                }
        }
Пример #20
0
        private void button3_Click(object sender, EventArgs e)
        {
            ProfileTree t = ProfileAutomatic.AnalyseProfileFile(profileFile, SIMDIST.SIMILARITY);

            if (t != null)
            {
                string profileName = "automatic_similarity.profile";
                t.SaveProfiles(profileName);
                userHash1.profRefFile             = profileName;
                userHash1.profRegFile             = profileName;
                distanceControl1.referenceProfile = profileName;
                if (distanceControl1.distDef == DistanceMeasures.HAMMING)
                {
                    t           = ProfileAutomatic.AnalyseProfileFile(profileFile, SIMDIST.DISTANCE);
                    profileName = "automatic_distance.profile";
                    t.SaveProfiles(profileName);
                    distanceControl1.profileName = profileName;
                }
            }
            else
            {
                MessageBox.Show("Profile cannot be generated");
            }
        }
Пример #21
0
 public Alignment()
 {
     r = new ProfileTree();
 }
Пример #22
0
        private string LabelActiveProfiles(string fileName)
        {
            string outStr = "";
            ProfileTree tree = new ProfileTree();
            if (fileName.Length > 0)
                tree.LoadProfiles(fileName);
            else
                return null;
            inputMode = tree.GetModes();
            List<profileNode> active = tree.GetActiveProfiles();
            outStr = "Active profiles: ";
            if(active!=null)
                for (int i = 0; i < active.Count; i++)
                {
                    outStr += active[i].profName;
                    if (i < active.Count - 1)
                        outStr += ", ";
                }

            return outStr;
        }
Пример #23
0
 public async Task Write(ProfileTree tree, CancellationToken cancellationToken) =>
 await inner.Write(tree.Ignore(ignore), cancellationToken);
        public static IEnumerable <IProfileEntry> WithImplicitHiddenKeys(this SchemeNode node, ProfileTree tree)
        {
            var originalPayload    = node.GetOriginalPayload().ToList();
            var implicitHiddenKeys = (from pair in tree.GetAllChildren()
                                      where IsArray(pair.tree)
                                      select new Payload(
                                          new QualifiedName(pair.prefix.Parts.Append(new NamePart(new[] { new TextNameToken("type") }))),
                                          new[] { new TextValueToken("hiddenKey") }, pair.tree.GetFirstSourceMark())).ToList();

            return(originalPayload.Concat(implicitHiddenKeys));
        }
Пример #25
0
        public static ProfileTree AnalyseProfileFile(string fileName, SIMDIST similarityFlag, string internalName = null)
        {
            ProfileTree t = new ProfileTree();

            StreamReader wr;

            if (fileName == null || !File.Exists(fileName))
            {
                throw new Exception("File:" + fileName + " not exists");
            }

            wr = new StreamReader(fileName);
            string line = wr.ReadLine();

            Dictionary <string, Dictionary <string, int> > dic = new Dictionary <string, Dictionary <string, int> >();

            while (line != null)
            {
                if (line.Contains(">"))
                {
                    line = wr.ReadLine();
                    while (line != null && line[0] != '>')
                    {
                        if (line.Contains("profile") && !line.Contains("SEQ"))
                        {
                            string[] tmp = line.Split(new string[] { " profile " }, StringSplitOptions.None);
                            if (!dic.ContainsKey(tmp[0]))
                            {
                                dic.Add(tmp[0], new Dictionary <string, int>());
                            }
                            string[] aux;
                            if (tmp[1].Contains(" "))
                            {
                                aux = tmp[1].Split(' ');
                            }
                            else
                            {
                                aux = new string[tmp[1].Length];
                                for (int i = 0; i < tmp[1].Length; i++)
                                {
                                    aux[i] = tmp[1][i].ToString();
                                }
                            }
                            foreach (var item in aux)
                            {
                                if (item != "-" && item != "")
                                {
                                    if (!dic[tmp[0]].ContainsKey(item))
                                    {
                                        dic[tmp[0]].Add(item, 0);
                                    }
                                }
                            }
                        }
                        line = wr.ReadLine();
                    }
                }
                else
                {
                    line = wr.ReadLine();
                }
            }
            wr.Close();

            if (dic.Keys.Count == 0)
            {
                throw new Exception("File " + fileName + " is not valid Profile file!");
            }

            foreach (var item in dic)
            {
                profileNode node = new profileNode();
                node.active = true;
                if (internalName != null)
                {
                    node.internalName = internalName;
                }
                else
                {
                    node.internalName = "User defined profile";
                }
                node.profName = item.Key;
                foreach (var itemK in item.Value)
                {
                    node.AddStateItem(itemK.Key, itemK.Key);
                }

                node.profWeights = GenerateWeights(new List <string>(item.Value.Keys), similarityFlag);
                t.AdddNode("/", node);
            }

            //  t.pr


            return(t);
        }
Пример #26
0
        public static ProfileTree AnalyseProfileFile(string fileName, SIMDIST similarityFlag)
        {
            ProfileTree t = new ProfileTree();

            StreamReader wr;
            if (fileName == null || !File.Exists(fileName))
                throw new Exception("File:" + fileName + " not exists");

            wr = new StreamReader(fileName);
            string line = wr.ReadLine();
            
            Dictionary<string, Dictionary<string, int>> dic = new Dictionary<string, Dictionary<string, int>>();
            while (line != null)
            {
                if (line.Contains(">"))
                {
                    line = wr.ReadLine();
                    while (line != null && line[0] != '>')
                    {
                        if (line.Contains("profile") && !line.Contains("SEQ"))
                        {
                            string[] tmp = line.Split(new string[] { " profile " }, StringSplitOptions.None);
                            if (!dic.ContainsKey(tmp[0]))
                                dic.Add(tmp[0], new Dictionary<string, int>());
                            string[] aux;
                            if (tmp[1].Contains(" "))
                                aux = tmp[1].Split(' ');
                            else
                            {
                                aux = new string[tmp[1].Length];
                                for (int i = 0; i < tmp[1].Length; i++)
                                    aux[i] = tmp[1][i].ToString();
                            }
                            foreach (var item in aux)
                                if (item != "-" && item!="")
                                    if (!dic[tmp[0]].ContainsKey(item))
                                           dic[tmp[0]].Add(item, 0);

                        }
                        line = wr.ReadLine();
                    }
                }
                else
                    line = wr.ReadLine();
            }
            wr.Close();

            if (dic.Keys.Count == 0)
                throw new Exception("File " + fileName + " is not valid Profile file!");

            foreach (var item in dic)
            {
                profileNode node = new profileNode();
                node.active = true;
                node.internalName = "User defined profile";
                node.profName = item.Key;
                foreach (var itemK in item.Value)
                    node.AddStateItem(itemK.Key, itemK.Key);

                node.profWeights = GenerateWeights(new List<string>(item.Value.Keys), similarityFlag);
                t.AdddNode("/", node);
            }

          //  t.pr


            return t;
        }
Пример #27
0
        private string LabelActiveProfiles(string fileName)
        {
            string outStr = "";
            ProfileTree tree = new ProfileTree();
            try
            {
                tree.LoadProfiles(fileName);
            }
            catch(Exception ex)
            {
                label2.Text = "";
            }
            inputMode = tree.GetModes();
            List<profileNode> active = tree.GetActiveProfiles();
            outStr = "Active profiles: ";
            if(active!=null)
                for (int i = 0; i < active.Count; i++)
                {
                    outStr += active[i].profName;
                    if (i < active.Count - 1)
                        outStr += ", ";
                }

            return outStr;
        }
Пример #28
0
        private void MakeViewCopy(ProfileTree tr,TreeNode node)
        {
            foreach (TreeNode item in node.Nodes)
            {
                string Path = item.FullPath;
                Path = PathRemoveRoot(Path);
                Path = ParentPath(Path);
                tr.AdddNode(Path, new profileNode((profileNode)item.Tag));

                if (item.Nodes.Count > 0)
                    MakeViewCopy(tr,item);


            }
        }
Пример #29
0
 protected abstract Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken);
Пример #30
0
        private void GetNodes(TreeNode node, ProfileTree tree)
        {
            profileNode nodeP;
            string parentPath = node.FullPath;
            Regex reg = new Regex("^Profiles");
            parentPath = reg.Replace(parentPath, "");
            foreach (TreeNode item in node.Nodes)
            {                
                string Path=item.FullPath;
                Path=reg.Replace(Path,"");
                nodeP=treeProfiles.FindNode(Path);
                tree.AdddNode(parentPath, new profileNode(nodeP));
                if (item.Nodes != null)
                    GetNodes(item, tree);

            }
        }