Esempio n. 1
0
        public void TestConvertToXMLNormalizedRoundtrip()
        {
            MemoryStream out1 = null;

            using (var input = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_BRKRTEST_MRC, FileMode.Open))
            {
                Assert.IsNotNull(input);
                out1 = new MemoryStream();
                MarcStreamReader marcReader = new MarcStreamReader(input);
                MarcXmlWriter    xmlWriter  = new MarcXmlWriter(out1);
                xmlWriter.Converter            = new AnselToUnicode();
                xmlWriter.UnicodeNormalization = true;
                while (marcReader.MoveNext())
                {
                    var record = marcReader.Current;
                    xmlWriter.Write(record);
                }
                input.Close();

                xmlWriter.Close();
                out1.Close();
            }
            using (MemoryStream out2 = new MemoryStream())
            {
                using (MemoryStream @in = new MemoryStream(out1.ToArray()))
                {
                    var xmlReader = new MarcXmlReader(@in).GetEnumerator();
                    MarcStreamWriter marcWriter = new MarcStreamWriter(out2);
                    marcWriter.Converter = new UnicodeToAnsel();
                    while (xmlReader.MoveNext())
                    {
                        var record = xmlReader.Current;
                        marcWriter.Write(record);
                    }
                    @in.Close();
                    marcWriter.Close();

                    out2.Close();

                    using (var inputCompare1 = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_BRKRTEST_MRC, FileMode.Open))
                    {
                        Assert.IsNotNull(inputCompare1);
                        var inputCompare2 = new MemoryStream(out2.ToArray());
                        MarcStreamReader readComp1 = new MarcStreamReader(inputCompare1);
                        MarcStreamReader readComp2 = new MarcStreamReader(inputCompare2);
                        IRecord          r1, r2;
                        do
                        {
                            r1 = (readComp1.MoveNext()) ? readComp1.Current : null;
                            r2 = (readComp2.MoveNext()) ? readComp2.Current : null;
                            if (r1 != null && r2 != null)
                            {
                                RecordTestingUtils.AssertEqualsIgnoreLeader(r1, r2);
                            }
                        } while (r1 != null && r2 != null);
                    }
                }
            }
        }
Esempio n. 2
0
 public void TestMarcXmlWriter()
 {
     using (var ms = new MemoryStream())
     {
         MarcXmlWriter writer = new MarcXmlWriter(ms, true);
         foreach (var record in StaticTestRecords.summerland)
         {
             writer.Write(record);
         }
         TestUtils.ValidateStringAgainstFile(Encoding.UTF8.GetString(ms.ToArray()), StaticTestRecords.RESOURCES_SUMMERLAND_XML);
     }
 }
Esempio n. 3
0
        public void TestWriteAndReadRoundtrip()
        {
            MemoryStream out2 = null;

            using (var input = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_CHABON_MRC, FileMode.Open))
            {
                Assert.IsNotNull(input);
                using (var out1 = new MemoryStream())
                {
                    MarcStreamReader marcReader = new MarcStreamReader(input);
                    using (MarcXmlWriter xmlWriter = new MarcXmlWriter(out1))
                    {
                        while (marcReader.MoveNext())
                        {
                            var record = marcReader.Current;
                            xmlWriter.Write(record);
                        }
                    }
                    out2 = new MemoryStream();
                    var @in       = new MemoryStream(out1.ToArray());
                    var xmlReader = new MarcXmlReader(@in).GetEnumerator();
                    MarcStreamWriter marcWriter = new MarcStreamWriter(out2);
                    while (xmlReader.MoveNext())
                    {
                        var record = xmlReader.Current;
                        marcWriter.Write(record);
                    }
                    @in.Close();
                }
            }
            using (var inputCompare1 = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_CHABON_MRC, FileMode.Open))
            {
                var     inputCompare2 = out2;
                var     readComp1 = new MarcStreamReader(inputCompare1);
                var     readComp2 = new MarcStreamReader(inputCompare2);
                IRecord r1, r2;
                do
                {
                    r1 = (readComp1.MoveNext()) ? readComp1.Current : null;
                    r2 = (readComp2.MoveNext()) ? readComp2.Current : null;
                    if (r1 != null && r2 != null)
                    {
                        RecordTestingUtils.AssertEqualsIgnoreLeader(r1, r2);
                    }
                } while (r1 != null && r2 != null);
            }
            out2.Dispose();
        }
Esempio n. 4
0
        public void TestMarcXmlWriter()
        {
            using (var ms = new MemoryStream())
            {
                MarcXmlWriter writer = new MarcXmlWriter(ms, true);
                foreach (var record in StaticTestRecords.summerland)
                {
                    writer.Write(record);
                }
                writer.Close();

                ms.Position = 0;
                using (var sr = new StreamReader(ms))
                    TestUtils.ValidateStringAgainstFile(sr.ReadToEnd(), StaticTestRecords.RESOURCES_SUMMERLAND_XML);
            }
        }
Esempio n. 5
0
        public void TestWriteOfRecordWithIndicatorlessSubfield()
        {
            var         record   = StaticTestRecords.GetSummerlandRecord();
            MarcFactory factory  = StaticTestRecords.getFactory();
            var         badField = factory.NewDataField();

            badField.Tag = "911";
            badField.AddSubfield(factory.NewSubfield('a', "HAZMARC - INDICATORLESS FIELD DETECTED - MOPP LEVEL 4"));
            record.AddVariableField(badField);

            using (var output = new MemoryStream())
            {
                using (MarcXmlWriter writer = new MarcXmlWriter(output, true))
                {
                    writer.Write(record);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Generiert aus volare Objekt-ID und Bild-URL ein MARC21 Katalogisat
        /// </summary>
        /// <param name="pUrlToImage">öffentlich erreichbare URL zum Bild</param>
        /// <param name="pOid">volare Objekt ID</param>
        public MARCGenerator(string pUrlToImage, string pOid)
        {
            _oid = pOid;
            Guid _guid = Guid.NewGuid();

            _marcFileName = _guid.ToString() + ".xml";
            _marcFilePath = MyConstants.PATHTOMARCFILES + _marcFileName;

            //Standardkatalogisat erstellen
            using (var fs2 = new FileStream(_marcFilePath, FileMode.OpenOrCreate))
            {
                using (var writer = new MarcXmlWriter(fs2, "UTF-8"))
                {
                    var record = MarcFactory.Instance.NewRecord();

                    //Personenerkennung
                    DTOCognitivePerson _personen = Helper.FaceHelper.IdentifyFaces(pUrlToImage);

                    //Objekterkennung
                    ObjectHelper _objekte = new ObjectHelper(pOid, pUrlToImage);

                    //Landeskundliche Elemente
                    CustomVisionHelper _landeskundliches = new CustomVisionHelper(pUrlToImage);

                    //Feld 007
                    record.AddVariableField(MarcFactory.Instance.NewControlField("007", string.Format("kv-ci|")));
                    record.AddVariableField(MarcFactory.Instance.NewControlField("007", string.Format("gs-c|||||")));

                    // Feld 008
                    if (_personen.GetEstimatedYear() != 0)
                    {
                        record.AddVariableField(MarcFactory.Instance.NewControlField("008", string.Format("150204q{0}----xx----------------f-zxx-d", _personen.GetEstimatedYear())));
                    }
                    else
                    {
                        record.AddVariableField(MarcFactory.Instance.NewControlField("008", string.Format("150204q19002020xx----------------f-zxx-d", _personen.GetEstimatedYear())));
                    }


                    // Feld 040
                    var _040 = MarcFactory.Instance.NewDataField("040", ' ', ' ');
                    _040.AddSubfield(MarcFactory.Instance.NewSubfield('a', "AT-VLB"));
                    _040.AddSubfield(MarcFactory.Instance.NewSubfield('b', "ger"));
                    _040.AddSubfield(MarcFactory.Instance.NewSubfield('d', "AT-VLB"));
                    _040.AddSubfield(MarcFactory.Instance.NewSubfield('e', "rda_VBV_Version_02"));
                    record.AddVariableField(_040);


                    // Feld 24510, Titel
                    var _24510 = MarcFactory.Instance.NewDataField("245", '1', '0');
                    _24510.AddSubfield(MarcFactory.Instance.NewSubfield('a', _objekte.GetImageSummary().Value));
                    record.AddVariableField(_24510);

                    // Feld 264 1
                    if (_personen.GetEstimatedYear() != 0)
                    {
                        var _264 = MarcFactory.Instance.NewDataField("264", ' ', '0');
                        _264.AddSubfield(MarcFactory.Instance.NewSubfield('c', _personen.GetEstimatedYear().ToString()));
                        _264.AddSubfield(MarcFactory.Instance.NewSubfield('9', "Anhand der abgebildeten Personen geschätzt"));
                        record.AddVariableField(_264);
                    }

                    //Feld 300
                    var _300 = MarcFactory.Instance.NewDataField("300", ' ', ' ');
                    _300.AddSubfield(MarcFactory.Instance.NewSubfield('a', "1 Digitales Bild"));
                    if (_objekte.IsImageBlackWhite())
                    {
                        _300.AddSubfield(MarcFactory.Instance.NewSubfield('b', "schwarz-weiß"));
                    }
                    else
                    {
                        _300.AddSubfield(MarcFactory.Instance.NewSubfield('b', "farbig"));
                    }

                    _300.AddSubfield(MarcFactory.Instance.NewSubfield('c', string.Format("{0} x {1} Pixel", _objekte.ImageWidth, _objekte.ImageHeight)));
                    record.AddVariableField(_300);

                    //Feld 336 (RDA!)
                    var _336 = MarcFactory.Instance.NewDataField("336", ' ', ' ');
                    _336.AddSubfield(MarcFactory.Instance.NewSubfield('a', "unbewegtes Bild"));
                    _336.AddSubfield(MarcFactory.Instance.NewSubfield('b', "sti"));
                    _336.AddSubfield(MarcFactory.Instance.NewSubfield('2', "rdacontent"));
                    record.AddVariableField(_336);

                    //Feld 337 (RDA!)
                    var _337 = MarcFactory.Instance.NewDataField("337", ' ', ' ');
                    _337.AddSubfield(MarcFactory.Instance.NewSubfield('a', "projizierbar"));
                    _337.AddSubfield(MarcFactory.Instance.NewSubfield('b', "g"));
                    _337.AddSubfield(MarcFactory.Instance.NewSubfield('2', "rdamedia"));
                    record.AddVariableField(_337);

                    //Feld 338 (RDA!)
                    var _338 = MarcFactory.Instance.NewDataField("338", ' ', ' ');
                    _338.AddSubfield(MarcFactory.Instance.NewSubfield('a', "Digitalisat"));
                    _338.AddSubfield(MarcFactory.Instance.NewSubfield('b', "gs"));
                    _338.AddSubfield(MarcFactory.Instance.NewSubfield('2', "rdacarrier"));
                    record.AddVariableField(_338);

                    //Feld 600 (Person)
                    foreach (CognitivePerson p in _personen.CognitivePeople)
                    {
                        if (p.pers.Name != "Unbekannt")
                        {
                            var _60014 = MarcFactory.Instance.NewDataField("600", '1', '4');
                            _60014.AddSubfield(MarcFactory.Instance.NewSubfield('a', p.pers.Name));
                            if (p.GetYearOfBirth() > 0)
                            {
                                if (p.GetYearOfDeath() > 0)
                                {
                                    _60014.AddSubfield(MarcFactory.Instance.NewSubfield('d', string.Format("{0}-{1}", p.GetYearOfBirth(), p.GetYearOfDeath())));
                                }
                                else
                                {
                                    _60014.AddSubfield(MarcFactory.Instance.NewSubfield('d', string.Format("{0}-", p.GetYearOfBirth())));
                                }
                            }
                            if (p.GetProfession() != string.Empty)
                            {
                                _60014.AddSubfield(MarcFactory.Instance.NewSubfield('g', p.GetProfession()));
                            }

                            if (p.pers.UserData != null)
                            {
                                _60014.AddSubfield(MarcFactory.Instance.NewSubfield('4', "(DE-588)" + p.pers.UserData));
                            }

                            record.AddVariableField(_60014);
                        }
                    }

                    // Feld 520 9, Tags
                    string _tags = string.Empty;
                    foreach (ObjectValue tags in _objekte.GetImageTags())
                    {
                        if (tags.Confidence > 50)
                        {
                            _tags += tags.Value + "; ";
                        }
                    }
                    if (_tags.Length > 1)
                    {
                        _tags = _tags.Substring(0, _tags.Length - 2);
                    }

                    var _5209 = MarcFactory.Instance.NewDataField("520", '9', ' ');
                    _5209.AddSubfield(MarcFactory.Instance.NewSubfield('a', _tags));
                    record.AddVariableField(_5209);


                    // Feld 520 9, Erkannter Text
                    if (_objekte.GetImageText() != string.Empty)
                    {
                        var _5209_2 = MarcFactory.Instance.NewDataField("520", '9', ' ');
                        _5209_2.AddSubfield(MarcFactory.Instance.NewSubfield('a', "Abgebildeter Text: " + _objekte.GetImageText()));
                        record.AddVariableField(_5209_2);
                    }

                    //Feld 659, Landeskundliche Elemente
                    foreach (CustomVisionValue cvv in _landeskundliches.MyCustomVisionValues)
                    {
                        if (cvv.Confidence > 98)
                        {
                            var _659 = MarcFactory.Instance.NewDataField("659", ' ', ' ');
                            _659.AddSubfield(MarcFactory.Instance.NewSubfield('a', cvv.Name));
                            if (cvv.GeonamesNumber.Length > 1)
                            {
                                _659.AddSubfield(MarcFactory.Instance.NewSubfield('u', cvv.GeonamesLink));
                            }
                            if (cvv.Lat != 0)
                            {
                                _659.AddSubfield(MarcFactory.Instance.NewSubfield('b', cvv.Lat.ToString().Replace(',', '.') + ", " + cvv.Lon.ToString().Replace(',', '.')));
                            }
                            record.AddVariableField(_659);
                        }
                    }

                    //856 LINK
                    var _856 = MarcFactory.Instance.NewDataField("856", '7', '0');
                    _856.AddSubfield(MarcFactory.Instance.NewSubfield('u', "https://pid.volare.vorarlberg.at/" + _oid));
                    _856.AddSubfield(MarcFactory.Instance.NewSubfield('z', "Digitalisat"));
                    _856.AddSubfield(MarcFactory.Instance.NewSubfield('2', "file"));
                    record.AddVariableField(_856);

                    //948 LINK
                    var _948 = MarcFactory.Instance.NewDataField("948", ' ', ' ');
                    _948.AddSubfield(MarcFactory.Instance.NewSubfield('a', "Vorarlberg-Sammlungen"));
                    record.AddVariableField(_948);

                    //948 LINK
                    var _931 = MarcFactory.Instance.NewDataField("931", ' ', ' ');
                    _931.AddSubfield(MarcFactory.Instance.NewSubfield('a', _oid));
                    record.AddVariableField(_931);

                    //TYP LINK
                    var _typ = MarcFactory.Instance.NewDataField("TYP", ' ', ' ');
                    _typ.AddSubfield(MarcFactory.Instance.NewSubfield('a', "Bildmaterial"));
                    record.AddVariableField(_typ);

                    _recordASString = record.ToString();

                    // Marc-XML-File auf Filesystem schreiben
                    writer.Write(record);
                }
            }
        }
Esempio n. 7
0
 public void TestMarcXmlWriterNormalized()
 {
     using (var ms = new MemoryStream())
     {
         using (var fs = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_BRKRTEST_MRC, FileMode.Open))
         {
             Assert.IsNotNull(fs);
             MarcXmlWriter writer = new MarcXmlWriter(fs, true);
             writer.Converter = new AnselToUnicode();
             MarcStreamReader reader = new MarcStreamReader(ms);
             while (reader.MoveNext())
             {
                 var record = reader.Current;
                 writer.Write(record);
             }
             using (StreamReader Testoutput = new StreamReader(fs, Encoding.UTF8))
             {
                 String line;
                 while ((line = Testoutput.ReadLine()) != null)
                 {
                     if (Regex.IsMatch(line, "[ ]*<subfield code=\"a\">This is a Test of diacritics.*"))
                     {
                         String[] lineParts = line.Split(new string[] { ", " }, StringSplitOptions.None);
                         foreach (var linePart in lineParts)
                         {
                             if (linePart.StartsWith("the tilde in "))
                             {
                                 Assert.IsTrue(linePart.Equals("the tilde in man\u0303ana"), "Incorrect value for tilde");
                             }
                             else if (linePart.StartsWith("the grave accent in "))
                             {
                                 Assert.IsTrue(linePart.Equals("the grave accent in tre\u0300s"), "Incorrect value for grave");
                             }
                             else if (linePart.StartsWith("the acute accent in "))
                             {
                                 Assert.IsTrue(linePart.Equals("the acute accent in de\u0301sire\u0301e"), "Incorrect value for acute");
                             }
                             else if (linePart.StartsWith("the circumflex in "))
                             {
                                 Assert.IsTrue(linePart.Equals("the circumflex in co\u0302te"), "Incorrect value for macron");
                             }
                             else if (linePart.StartsWith("the macron in "))
                             {
                                 Assert.IsTrue(linePart.Equals("the macron in To\u0304kyo"), "Incorrect value for macron");
                             }
                             else if (linePart.StartsWith("the breve in "))
                             {
                                 Assert.IsTrue(linePart.Equals("the breve in russkii\u0306"), "Incorrect value for breve");
                             }
                             else if (linePart.StartsWith("the dot above in "))
                             {
                                 Assert.IsTrue(linePart.Equals("the dot above in z\u0307aba"), "Incorrect value for dot above");
                             }
                             else if (linePart.StartsWith("the dieresis (umlaut) in "))
                             {
                                 Assert.IsTrue(linePart.Equals("the dieresis (umlaut) in Lo\u0308wenbra\u0308u"), "Incorrect value for umlaut");
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 8
0
 public void TestMarcXmlWriterConvertedToUTF8AndNormalized()
 {
     using (var output = new MemoryStream())
     {
         using (var fs = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_BRKRTEST_MRC, FileMode.Open))
         {
             Assert.IsNotNull(fs);
             MarcXmlWriter writer = new MarcXmlWriter(output, true);
             writer.Converter            = new AnselToUnicode();
             writer.UnicodeNormalization = true;
             MarcStreamReader reader = new MarcStreamReader(fs);
             while (reader.MoveNext())
             {
                 var record = reader.Current;
                 writer.Write(record);
             }
             using (StreamReader Testoutput = new StreamReader(fs, Encoding.UTF8))
             {
                 String line;
                 while ((line = Testoutput.ReadLine()) != null)
                 {
                     if (Regex.IsMatch(line, "[ ]*<subfield code=\"a\">This is a Test of diacritics.*"))
                     {
                         String[] lineParts = line.Split(new string[] { ", " }, StringSplitOptions.None);
                         for (int i = 0; i < lineParts.Length; i++)
                         {
                             if (lineParts[i].StartsWith("the tilde in "))
                             {
                                 Assert.IsTrue(lineParts[i].Equals("the tilde in ma\u00F1ana"), "Incorrect normalized value for tilde accent");
                             }
                             else if (lineParts[i].StartsWith("the grave accent in "))
                             {
                                 Assert.IsTrue(lineParts[i].Equals("the grave accent in tr\u00E8s"), "Incorrect normalized value for grave accent");
                             }
                             else if (lineParts[i].StartsWith("the acute accent in "))
                             {
                                 Assert.IsTrue(lineParts[i].Equals("the acute accent in d\u00E9sir\u00E9e"), "Incorrect normalized value for acute accent");
                             }
                             else if (lineParts[i].StartsWith("the circumflex in "))
                             {
                                 Assert.IsTrue(lineParts[i].Equals("the circumflex in c\u00F4te"), "Incorrect normalized value for circumflex");
                             }
                             else if (lineParts[i].StartsWith("the macron in "))
                             {
                                 Assert.IsTrue(lineParts[i].Equals("the macron in T\u014Dkyo"), "Incorrect normalized value for macron");
                             }
                             else if (lineParts[i].StartsWith("the breve in "))
                             {
                                 Assert.IsTrue(lineParts[i].Equals("the breve in russki\u012D"), "Incorrect normalized value for breve");
                             }
                             else if (lineParts[i].StartsWith("the dot above in "))
                             {
                                 Assert.IsTrue(lineParts[i].Equals("the dot above in \u017Caba"), "Incorrect normalized value for dot above");
                             }
                             else if (lineParts[i].StartsWith("the dieresis (umlaut) in "))
                             {
                                 Assert.IsTrue(lineParts[i].Equals("the dieresis (umlaut) in L\u00F6wenbr\u00E4u"), "Incorrect normalized value for umlaut");
                             }
                         }
                     }
                 }
             }
         }
     }
 }