Changeset 1426


Ignore:
Timestamp:
May 13, 2010, 11:53:23 AM (12 years ago)
Author:
malischewski
Message:

Added support for multiple language files used for generation of Bigram/Trigram statistics, German/English for now.
Added support for custom (selected by user) language files for Bigram/Trigram statistics.

Location:
trunk/CrypPlugins/CostFunction
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/CostFunction/CostFunction.cs

    r1376 r1426  
    2929using System.Text.RegularExpressions;
    3030using System.Threading;
     31using System.Reflection;
    3132namespace Cryptool.Plugins.CostFunction
    3233{
     
    4950        private IDictionary<string, double[]> corpusTrigrams;
    5051
    51         private DataManager dataMgr = new DataManager();
     52        private DataManager dataMgr = new DataManager(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
    5253        private const string DATATYPE = "transposition";
    5354
     
    525526            return NativeCryptography.Crypto.calculateEntropy(text, bytesToUse);
    526527            if (bytesToUse > text.Length)
     528           
    527529                bytesToUse = text.Length;
    528 
     530           
    529531            if (lastUsedSize != bytesToUse)
    530532            {
     
    609611        private IDictionary<string, double[]> LoadDefaultStatistics(int length)
    610612        {
     613           
    611614            txtList = dataMgr.LoadDirectory(DATATYPE);
    612 
    613             return calculateAbsolutes(txtList["2gram.txt"].DataFile.FullName, length);
     615           
     616            switch (this.settings.StatisticsCorpus)
     617            {
     618                case 0:
     619                    return calculateAbsolutes(txtList["statisticscorpusde"].DataFile.FullName, length);
     620                   
     621                case 1:
     622                    return calculateAbsolutes(txtList["statisticscorpusen"].DataFile.FullName, length);
     623                case 2:
     624                    return calculateAbsolutes(this.settings.customFilePath, length);
     625
     626            }
     627            return calculateAbsolutes(txtList["Statistics (DE)"].DataFile.FullName, length); //default
     628           
    614629        }
    615630
  • trunk/CrypPlugins/CostFunction/CostFunction.csproj

    r1416 r1426  
    113113      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    114114    </Reference>
     115    <Reference Include="System.Windows.Forms" />
    115116    <Reference Include="System.Xaml" />
    116117    <Reference Include="System.Xml.Linq">
     
    142143  </ItemGroup>
    143144  <ItemGroup>
     145    <None Include="Data\StatisticsCorpusEN">
     146      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     147    </None>
     148    <None Include="Data\StatisticsCorpusEN.metainfo">
     149      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     150    </None>
    144151    <None Include="Enigma_1gram_Frequency.txt">
    145152      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     
    162169  </ItemGroup>
    163170  <ItemGroup>
    164     <None Include="Data\2gram.txt">
     171    <None Include="Data\StatisticsCorpusDE">
    165172      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    166173    </None>
     
    172179  </ItemGroup>
    173180  <ItemGroup>
    174     <None Include="Data\2gram.txt.metainfo" />
     181    <None Include="Data\StatisticsCorpusDE.metainfo">
     182      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     183    </None>
    175184  </ItemGroup>
    176185  <ItemGroup>
     
    200209  -->
    201210  <PropertyGroup>
    202     <PostBuildEvent>
    203     </PostBuildEvent>
     211    <PostBuildEvent>if not exist "./Data/transposition" mkdir "./Data/transposition"
     212
     213copy "$(TargetDir)CostFunction*.*" "./CrypPlugins"
     214copy "$(ProjectDir)Data\*.*" "./Data/transposition"</PostBuildEvent>
    204215  </PropertyGroup>
    205216</Project>
  • trunk/CrypPlugins/CostFunction/CostFunctionSettings.cs

    r1375 r1426  
    2323using System.Collections.ObjectModel;
    2424using System.Windows;
     25using Cryptool.PluginBase.Miscellaneous;
     26
     27using System.Windows.Forms;
    2528
    2629namespace Cryptool.Plugins.CostFunction
     
    3336        private String bytesToUse = "256";
    3437        private int bytesToUseInteger = 256;
     38
     39        private static DataManager dataMgr = new DataManager();
     40        private const string DATATYPE = "transposition";
     41        private static IDictionary<String, DataFileMetaInfo> txtList;
     42        private static string[] files;
    3543        #endregion
    36        
     44   
    3745        [TaskPane("FunctionType", "Select the type of function", null, 1, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "Index of coincidence", "Entropy", "Bigrams: log 2", "Bigrams: Sinkov", "Bigrams: Percentaged", "Regular Expression", "Weighted Bigrams/Trigrams"})]
    3846        public int FunctionType
     
    6775        }
    6876
     77
     78        public string customFilePath;
     79        public int statisticscorpus = 0;
     80        [TaskPane("Text Corpus File to use", "Select a text corpus file (Default is (DE))", null, 7, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "Text corpus (DE)", "Text corpus (EN)", "Custom (...)" })]
     81        public int StatisticsCorpus
     82        {
     83            get
     84            {
     85              return statisticscorpus;
     86            }
     87            set
     88            {
     89                statisticscorpus = value;
     90                if (statisticscorpus == 2)
     91                {
     92                   
     93
     94                    OpenFileDialog openCorpusFile = new OpenFileDialog();
     95                    openCorpusFile.Title = "Select text corpus file";
     96                    openCorpusFile.CheckFileExists = true;
     97                    openCorpusFile.CheckPathExists = true;
     98                    openCorpusFile.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
     99                    if (openCorpusFile.ShowDialog() == DialogResult.OK)
     100                    {
     101                        customFilePath = openCorpusFile.FileName;
     102                    }
     103                    else
     104                    {
     105                        statisticscorpus = 0; // Fall back to default
     106                    }
     107                }
     108                UpdateTaskPaneVisibility();
     109                OnPropertyChanged("StatisticsCorpus");
     110            }
     111        }
     112       
    69113        public event TaskPaneAttributeChangedHandler TaskPaneAttributeChanged;
    70114
     
    86130                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("RegEx", Visibility.Collapsed)));
    87131            }
     132
     133            if (functionType.Equals(4) || functionType.Equals(2) || functionType.Equals(3) || functionType.Equals(6))
     134            {
     135                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("StatisticsCorpus", Visibility.Visible)));
     136
     137            }
     138            else
     139            {
     140                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("StatisticsCorpus", Visibility.Collapsed)));
     141               
     142            }
     143           
    88144
    89145        }
Note: See TracChangeset for help on using the changeset viewer.