Esempio n. 1
0
        private static void ConvertEachBibTexPairIntoWord2007Pair(XmlDocument doc, XmlNode node_source, string fields)
        {
            List <string> field_list = SplitFields(fields);

            foreach (string field in field_list)
            {
                string[] field_split = field.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
                if (2 != field_split.Length)
                {
                    Logging.Warn("Unable to process BibTex field '{0}'", field);
                }
                else
                {
                    string key = field_split[0].Trim();
                    string val = field_split[1].Trim();
                    val = val.TrimStart('{').TrimEnd('}');
                    val = BibTexCharacterMap.BibTexToASCII(val);

                    string  field_type_word2007 = TranslateFieldType(key);
                    XmlNode node_record         = doc.CreateElement(NS_TAG, field_type_word2007, NS);

                    // Process authors specifically
                    if (key.Equals("author"))
                    {
                        XmlNode node_name_list = doc.CreateElement(NS_TAG, "NameList", NS);

                        XmlNode node_author = doc.CreateElement(NS_TAG, "Author", NS);
                        node_author.AppendChild(node_name_list);

                        node_record.AppendChild(node_author);

                        string[] authors = NameTools.SplitAuthors_LEGACY(val);
                        foreach (string author in authors)
                        {
                            string first_name;
                            string last_name;
                            NameTools.SplitName_LEGACY(author, out first_name, out last_name);

                            XmlNode node_last = doc.CreateElement(NS_TAG, "Last", NS);
                            node_last.AppendChild(doc.CreateTextNode(last_name));

                            XmlNode node_first = doc.CreateElement(NS_TAG, "First", NS);
                            node_first.AppendChild(doc.CreateTextNode(first_name));

                            XmlNode node_person = doc.CreateElement(NS_TAG, "Person", NS);
                            node_person.AppendChild(node_last);
                            node_person.AppendChild(node_first);

                            node_name_list.AppendChild(node_person);
                        }
                    }
                    else
                    {
                        node_record.AppendChild(doc.CreateTextNode(val));
                    }

                    node_source.AppendChild(node_record);
                }
            }
        }
Esempio n. 2
0
        public void Test_Conversion_To_And_From_BibTeX_Text()
        {
            string s1 = TestStringS1;
            string s2 = BibTexCharacterMap.ASCIIToBibTex(s1);
            string s3 = BibTexCharacterMap.BibTexToASCII(s2);

            ASSERT.AreEqual(s1, s3);
        }
Esempio n. 3
0
        public void Test_SPEED(string filepath)
        {
            string path = GetNormalizedPathToAnyTestDataTestFile(filepath);

            ASSERT.FileExists(path);

            string data_in = GetTestFileContent(path);
            string s1      = data_in;
            string s2      = BibTexCharacterMap.ASCIIToBibTex(s1);
            string s3      = BibTexCharacterMap.BibTexToASCII(s2);

            const int NUM   = 1000000;
            const int CHUNK = 10000;
            Stopwatch start = Stopwatch.StartNew();
            int       i;

            for (i = 0; i < NUM; ++i)
            {
                if (i % CHUNK == CHUNK - 1)
                {
                    // don't run for more than 2 seconds
                    if (start.ElapsedMilliseconds >= 2000)
                    {
                        break;
                    }
                }
                s2 = BibTexCharacterMap.ASCIIToBibTex(s1);
            }
            double time_a2b = i * 1.0E-3 * s1.Length / start.ElapsedMilliseconds;

            Logging.Info("ASCIIToBibTex can do {0:0.000}M operations per second per character", time_a2b);

            start = Stopwatch.StartNew();
            for (i = 0; i < NUM; ++i)
            {
                if (i % CHUNK == CHUNK - 1)
                {
                    // don't run for more than 2 seconds
                    if (start.ElapsedMilliseconds >= 2000)
                    {
                        break;
                    }
                }
                s3 = BibTexCharacterMap.BibTexToASCII(s2);
            }
            double time_b2a = i * 1.0E-3 * s1.Length / start.ElapsedMilliseconds;

            Logging.Info("BibTexToASCII can do {0:0.000}M operations per second per character", time_b2a);

            // dummy
            BibTexCharacterMap.ASCIIToBibTex(s3);
        }
Esempio n. 4
0
        public void Test_Conversion_To_BibTeX_Text(string filepath)
        {
            string path = GetNormalizedPathToAnyTestDataTestFile(filepath);

            ASSERT.FileExists(path);

            string data_in = GetTestFileContent(path);
            string s1      = data_in;
            string s2      = BibTexCharacterMap.ASCIIToBibTex(s1);

            ApprovalTests.Approvals.Verify(
                new QiqqaApprover(s2, filepath),
                ApprovalTests.Approvals.GetReporter()
                );
        }
Esempio n. 5
0
        public void Test_SPEED()
        {
            string s1 = TestStringS1;
            string s2 = BibTexCharacterMap.ASCIIToBibTex(s1);
            string s3 = BibTexCharacterMap.BibTexToASCII(s2);

            const int NUM   = 1000000;
            const int CHUNK = 10000;
            Stopwatch start = Stopwatch.StartNew();
            int       i;

            for (i = 0; i < NUM; ++i)
            {
                if (i % CHUNK == CHUNK - 1)
                {
                    // don't run for more than 2 seconds
                    if (start.ElapsedMilliseconds >= 2000)
                    {
                        break;
                    }
                }
                s2 = BibTexCharacterMap.ASCIIToBibTex(s1);
            }
            double time_a2b = i * 1.0E-3 * s1.Length / start.ElapsedMilliseconds;

            Logging.Info("ASCIIToBibTex can do {0:0.000}M operations per second per character", time_a2b);

            start = Stopwatch.StartNew();
            for (i = 0; i < NUM; ++i)
            {
                if (i % CHUNK == CHUNK - 1)
                {
                    // don't run for more than 2 seconds
                    if (start.ElapsedMilliseconds >= 2000)
                    {
                        break;
                    }
                }
                s3 = BibTexCharacterMap.BibTexToASCII(s2);
            }
            double time_b2a = i * 1.0E-3 * s1.Length / start.ElapsedMilliseconds;

            Logging.Info("BibTexToASCII can do {0:0.000}M operations per second per character", time_b2a);

            // dummy
            BibTexCharacterMap.ASCIIToBibTex(s3);
        }