Beispiel #1
0
/*
 *              public static void LoadRedefinedMemberFunctions( Fuzzifier fuzzifier, string file )
 *              {
 *                      try
 *                      {
 * //				fuzzifier.m_MembershipFunctions.Clear();
 *
 *                              StreamReader reader = new StreamReader( file );
 *                              string line;
 *                              char[] separator = {' ', '\t', '\n'};
 *                              string[] tokens;
 *                              while ( ( line = reader.ReadLine() ) != null )
 *                              {
 *                                      line = line.Trim();
 *                                      if ( line.Length > 0 && line[0] != ';' )
 *                                      {
 *                                              tokens = line.Split( separator );
 *                                              MfInterface[] memberFuncToWrap = fuzzifier.GetMembershipFunctions( tokens[1] );
 *
 *                                              for ( int i = 0; i < memberFuncToWrap.Length; i++ )
 *                                              {
 *                                                      MfInterface wrapperMf = new RedefinedMemberFunction( tokens[0], memberFuncToWrap[i] );
 *                                                      fuzzifier.AddMembershipFunction( wrapperMf );
 *                                              }
 *                                      }
 *                              }
 *                              reader.Close();
 *                      }
 *                      catch ( Exception e )
 *                      {
 *                              LogWriter.Write( e.ToString() );
 *                      }
 *              }
 */

        public static void SaveMemberFunctions(Fuzzifier fuzzifier, string file)
        {
            try
            {
                StreamWriter writer = new StreamWriter(file, false);

                IDictionaryEnumerator htEnumerator = fuzzifier.m_MembershipFunctions.GetEnumerator();
                while (htEnumerator.MoveNext())
                {
                    ArrayList currentFunctions = ( ArrayList )htEnumerator.Value;
                    for (int i = 0; i < currentFunctions.Count; i++)
                    {
                        string      locked           = "";
                        MfInterface memberFuncToSave = ( MfInterface )currentFunctions[i];

                        if (memberFuncToSave.IsLocked())
                        {
                            locked = " *";
                        }

                        if (memberFuncToSave.SaveAble())
                        {
                            writer.WriteLine(memberFuncToSave.VariableName() + " " + memberFuncToSave.TermName() + " " + memberFuncToSave.BaseLeft() + " " + memberFuncToSave.CenterMax() + " " + memberFuncToSave.BaseRight() + locked);
                        }
                    }
                }
                writer.Close();
            }
            catch (Exception)
            {}
        }
Beispiel #2
0
 public int GetMembershipFunctionId(string linguisticVar, string linguisticTerm)
 {
     for (int i = 0; i < MemberFunctionsCount(); i++)
     {
         MfInterface mf = GetMembershipFunction(i);
         if (mf.VariableName().Equals(linguisticVar) && mf.TermName().Equals(linguisticTerm))
         {
             return(i);
         }
     }
     return(-1);
 }
Beispiel #3
0
 public void AddMembershipFunction(MfInterface memberFunc)
 {
     if (m_MembershipFunctions.ContainsKey(memberFunc.VariableName()))
     {
         ArrayList al = ( ArrayList )m_MembershipFunctions[memberFunc.VariableName()];
         for (int i = 0; i < al.Count; i++)
         {
             if ((( MfInterface )al[i]).TermName().Equals(memberFunc.TermName()))
             {
                 return;
             }
         }
         al.Add(memberFunc);
         m_MfKeys.Add(new MfKey(memberFunc.VariableName(), memberFunc.TermName()));
     }
     else
     {
         ArrayList al = new ArrayList();
         al.Add(memberFunc);
         m_MembershipFunctions.Add(memberFunc.VariableName(), al);
         m_MfKeys.Add(new MfKey(memberFunc.VariableName(), memberFunc.TermName()));
     }
 }
Beispiel #4
0
 public void AddMembershipFunction( MfInterface memberFunc )
 {
     if ( m_MembershipFunctions.ContainsKey( memberFunc.VariableName() ) )
     {
         ArrayList al = ( ArrayList )m_MembershipFunctions[memberFunc.VariableName()];
         for ( int i = 0; i < al.Count; i++ )
             if ( ( ( MfInterface )al[i] ).TermName().Equals( memberFunc.TermName() ) )
                 return;
         al.Add( memberFunc );
         m_MfKeys.Add( new MfKey( memberFunc.VariableName(), memberFunc.TermName() ) );
     }
     else
     {
         ArrayList al = new ArrayList();
         al.Add( memberFunc );
         m_MembershipFunctions.Add( memberFunc.VariableName(), al );
         m_MfKeys.Add( new MfKey( memberFunc.VariableName(), memberFunc.TermName() ) );
     }
 }