private static void read_subject_object(XmlReader r, Bibliographic_Info thisBibInfo)
        {
            string language = String.Empty;
            string authority = String.Empty;
            string id = String.Empty;

            if (r.MoveToAttribute("ID"))
                id = r.Value;
            if (r.MoveToAttribute("lang"))
                language = r.Value;
            if (r.MoveToAttribute("authority"))
                authority = r.Value;

            // Move to the next element
            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                    break;
            }

            // Determine the subject type
            Subject_Info_Type type = Subject_Info_Type.UNKNOWN;

            // What is the name of this node?
            switch (r.Name)
            {
                case "mods:topic":
                case "mods:geographic":
                case "mods:genre":
                case "mods:temporal":
                case "mods:occupation":
                case "topic":
                case "geographic":
                case "genre":
                case "temporal":
                case "occupation":
                    type = Subject_Info_Type.Standard;
                    break;

                case "mods:hierarchicalGeographic":
                case "hierarchicalGeographic":
                    type = Subject_Info_Type.Hierarchical_Spatial;
                    break;

                case "mods:cartographics":
                case "cartographics":
                    type = Subject_Info_Type.Cartographics;
                    break;

                case "mods:name":
                case "name":
                    type = Subject_Info_Type.Name;
                    break;

                case "mods:titleInfo":
                case "titleInfo":
                    type = Subject_Info_Type.TitleInfo;
                    break;
            }

            // If no type was determined, return null
            if (type == Subject_Info_Type.UNKNOWN)
                return;

            // Was this the standard subject object?
            if (type == Subject_Info_Type.Standard)
            {
                Subject_Info_Standard standardSubject = new Subject_Info_Standard();
                standardSubject.Language = language;
                standardSubject.Authority = authority;
                standardSubject.ID = id;

                do
                {
                    if ((r.NodeType == XmlNodeType.EndElement) && ((r.Name == "mods:subject") || (r.Name == "subject")))
                    {
                        if ((standardSubject.Topics_Count > 0) || (standardSubject.Geographics_Count > 0) || (standardSubject.Genres_Count > 0) ||
                            (standardSubject.Temporals_Count > 0) || (standardSubject.Occupations_Count > 0))
                        {
                            thisBibInfo.Add_Subject(standardSubject);
                        }
                        return;
                    }

                    if (r.NodeType == XmlNodeType.Element)
                    {
                        switch (r.Name)
                        {
                            case "mods:topic":
                            case "topic":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    standardSubject.Add_Topic(r.Value);
                                break;

                            case "mods:geographic":
                            case "geographic":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    standardSubject.Add_Geographic(r.Value);
                                break;

                            case "mods:genre":
                            case "genre":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    standardSubject.Add_Genre(r.Value);
                                break;

                            case "mods:temporal":
                            case "temporal":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    standardSubject.Add_Temporal(r.Value);
                                break;

                            case "mods:occupation":
                            case "occupation":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    standardSubject.Add_Occupation(r.Value);
                                break;
                        }
                    }
                } while (r.Read());
            }

            // Was this the hierarchical geography subject?
            if (type == Subject_Info_Type.Hierarchical_Spatial)
            {
                Subject_Info_HierarchicalGeographic geoSubject = new Subject_Info_HierarchicalGeographic();
                geoSubject.Language = language;
                geoSubject.Authority = authority;
                geoSubject.ID = id;

                while (r.Read())
                {
                    if ((r.NodeType == XmlNodeType.EndElement) && ((r.Name == "mods:subject") || (r.Name == "subject")))
                    {
                        thisBibInfo.Add_Subject(geoSubject);
                        return;
                    }

                    if (r.NodeType == XmlNodeType.Element)
                    {
                        switch (r.Name)
                        {
                            case "mods:continent":
                            case "continent":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.Continent = r.Value;
                                break;

                            case "mods:country":
                            case "country":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.Country = r.Value;
                                break;

                            case "mods:province":
                            case "province":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.Province = r.Value;
                                break;

                            case "mods:region":
                            case "region":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.Region = r.Value;
                                break;

                            case "mods:state":
                            case "state":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.State = r.Value;
                                break;

                            case "mods:territory":
                            case "territory":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.Territory = r.Value;
                                break;

                            case "mods:county":
                            case "county":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.County = r.Value;
                                break;

                            case "mods:city":
                            case "city":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.City = r.Value;
                                break;

                            case "mods:citySection":
                            case "citySection":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.CitySection = r.Value;
                                break;

                            case "mods:island":
                            case "island":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.Island = r.Value;
                                break;

                            case "mods:area":
                            case "area":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    geoSubject.Area = r.Value;
                                break;
                        }
                    }
                }
            }

            // Was this the cartographics subject?
            if (type == Subject_Info_Type.Cartographics)
            {
                Subject_Info_Cartographics mapSubject = new Subject_Info_Cartographics();
                mapSubject.Language = language;
                mapSubject.Authority = authority;
                mapSubject.ID = id;

                while (r.Read())
                {
                    if ((r.NodeType == XmlNodeType.EndElement) && ((r.Name == "mods:subject") || (r.Name == "subject")))
                    {
                        if ((mapSubject.Projection.Length > 0) || (mapSubject.Coordinates.Length > 0) || (mapSubject.Scale.Length > 0))
                        {
                            thisBibInfo.Add_Subject(mapSubject);
                        }
                        return;
                    }

                    if (r.NodeType == XmlNodeType.Element)
                    {
                        switch (r.Name)
                        {
                            case "mods:coordinates":
                            case "coordinates":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    mapSubject.Coordinates = r.Value;
                                break;

                            case "mods:scale":
                            case "scale":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    mapSubject.Scale = r.Value;
                                break;

                            case "mods:projection":
                            case "projection":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    mapSubject.Projection = r.Value;
                                break;
                        }
                    }
                }
            }

            // Was this the name subject?
            if (type == Subject_Info_Type.Name)
            {
                Subject_Info_Name nameSubject = new Subject_Info_Name();
                nameSubject.Language = language;
                nameSubject.Authority = authority;
                nameSubject.ID = id;

                do
                {
                    if ((r.NodeType == XmlNodeType.EndElement) && ((r.Name == "mods:subject") || (r.Name == "subject")))
                    {
                        thisBibInfo.Add_Subject(nameSubject);
                        return;
                    }

                    if (r.NodeType == XmlNodeType.Element)
                    {
                        switch (r.Name)
                        {
                            case "mods:name":
                            case "name":
                                Name_Info nameInfo = read_name_object(r);
                                nameSubject.Set_Internal_Name(nameInfo);
                                break;

                            case "mods:topic":
                            case "topic":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    nameSubject.Add_Topic(r.Value);
                                break;

                            case "mods:geographic":
                            case "geographic":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    nameSubject.Add_Geographic(r.Value);
                                break;

                            case "mods:genre":
                            case "genre":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    nameSubject.Add_Genre(r.Value);
                                break;

                            case "mods:temporal":
                            case "temporal":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    nameSubject.Add_Temporal(r.Value);
                                break;
                        }
                    }
                } while (r.Read());
            }

            // Was this the title subject?
            if (type == Subject_Info_Type.TitleInfo)
            {
                Subject_Info_TitleInfo titleSubject = new Subject_Info_TitleInfo();
                titleSubject.Language = language;
                titleSubject.Authority = authority;
                titleSubject.ID = id;

                do
                {
                    if ((r.NodeType == XmlNodeType.EndElement) && ((r.Name == "mods:subject") || (r.Name == "subject")))
                    {
                        thisBibInfo.Add_Subject(titleSubject);
                        return;
                    }

                    if (r.NodeType == XmlNodeType.Element)
                    {
                        switch (r.Name)
                        {
                            case "mods:titleInfo":
                            case "titleInfo":
                                Title_Info titleInfo = read_title_object(r);
                                titleSubject.Set_Internal_Title(titleInfo);
                                break;

                            case "mods:topic":
                            case "topic":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    titleSubject.Add_Topic(r.Value);
                                break;

                            case "mods:geographic":
                            case "geographic":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    titleSubject.Add_Geographic(r.Value);
                                break;

                            case "mods:genre":
                            case "genre":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    titleSubject.Add_Genre(r.Value);
                                break;

                            case "mods:temporal":
                            case "temporal":
                                r.Read();
                                if (r.NodeType == XmlNodeType.Text)
                                    titleSubject.Add_Temporal(r.Value);
                                break;
                        }
                    }
                } while (r.Read());
            }
        }
        private static void Add_Main_Title(Bibliographic_Info thisBibInfo, MARC_Record record, int tag, Title_Type_Enum type, int non_filling_type, int title_type)
        {
            // Step through each instance of this tag
            foreach (MARC_Field thisRecord in record[tag])
            {
                // Declare new title
                Title_Info newTitle = new Title_Info();
                newTitle.Title_Type = type;

                switch (non_filling_type)
                {
                    case 0:
                        newTitle.Title = Remove_Trailing_Punctuation(thisRecord['a']);
                        break;

                    case 1:
                        int non_filling_chars1 = 0;
                        try
                        {
                            non_filling_chars1 = Convert.ToInt16(thisRecord.Indicator1) - 48;
                        }
                        catch
                        {
                        }

                        if (non_filling_chars1 == 0)
                        {
                            newTitle.Title = Remove_Trailing_Punctuation(thisRecord['a']);
                        }
                        else
                        {
                            string complete_title = thisRecord['a'];
                            newTitle.NonSort = complete_title.Substring(0, non_filling_chars1);
                            newTitle.Title = Remove_Trailing_Punctuation(complete_title.Substring(non_filling_chars1));
                        }
                        break;

                    case 2:
                        int non_filling_chars2 = 0;
                        try
                        {
                            non_filling_chars2 = Convert.ToInt16(thisRecord.Indicator2) - 48;
                        }
                        catch
                        {
                        }

                        if (non_filling_chars2 == 0)
                        {
                            newTitle.Title = Remove_Trailing_Punctuation(thisRecord['a']);
                        }
                        else
                        {
                            string complete_title = thisRecord['a'];
                            newTitle.NonSort = complete_title.Substring(0, non_filling_chars2);
                            newTitle.Title = Remove_Trailing_Punctuation(complete_title.Substring(non_filling_chars2));
                        }
                        break;
                }

                newTitle.Title = newTitle.Title.Replace("âE", "É");

                if (thisRecord.has_Subfield('b'))
                    newTitle.Subtitle = Remove_Trailing_Punctuation(thisRecord['b'].Replace("/", ""));
                if (thisRecord.has_Subfield('n'))
                    newTitle.Add_Part_Number(thisRecord['n']);
                if (thisRecord.has_Subfield('p'))
                    newTitle.Add_Part_Name(thisRecord['p']);
                if (thisRecord.has_Subfield('y'))
                    newTitle.Language = thisRecord['y'];
                if (tag >= 700)
                    newTitle.Display_Label = "Uncontrolled";
                if (tag < 200)
                    newTitle.Display_Label = "Main Entry";
                if (tag == 246)
                {
                    switch (thisRecord.Indicator2)
                    {
                        case '0':
                            newTitle.Display_Label = "Portion of title";
                            break;

                        case '1':
                            newTitle.Display_Label = "Parallel title";
                            break;

                        case '2':
                            newTitle.Display_Label = "Distinctive title";
                            break;

                        case '3':
                            newTitle.Display_Label = "Other title";
                            break;

                        case '4':
                            newTitle.Display_Label = "Cover title";
                            break;

                        case '5':
                            newTitle.Display_Label = "Added title page title";
                            break;

                        case '6':
                            newTitle.Display_Label = "Caption title";
                            break;

                        case '7':
                            newTitle.Display_Label = "Running title";
                            break;

                        case '8':
                            newTitle.Display_Label = "Spine title";
                            break;

                        default:
                            newTitle.Display_Label = "Alternate title";
                            break;
                    }
                }
                if (thisRecord.has_Subfield('i'))
                    newTitle.Display_Label = thisRecord['i'].Replace(":", "");

                switch (title_type)
                {
                    case 1:
                        thisBibInfo.Main_Title = newTitle;
                        break;

                    case 2:
                        thisBibInfo.Add_Other_Title(newTitle);
                        break;

                    case 3:
                        thisBibInfo.SeriesTitle = newTitle;
                        break;

                    case 4:
                        Subject_Info_TitleInfo newTitleSubj = new Subject_Info_TitleInfo();
                        newTitleSubj.Set_Internal_Title(newTitle);
                        if (thisRecord.has_Subfield('v'))
                            newTitleSubj.Add_Genre(Remove_Trailing_Punctuation(thisRecord['v']));
                        if (thisRecord.has_Subfield('x'))
                            newTitleSubj.Add_Topic(Remove_Trailing_Punctuation(thisRecord['x']));
                        if (thisRecord.has_Subfield('y'))
                            newTitleSubj.Add_Temporal(Remove_Trailing_Punctuation(thisRecord['y']));
                        if (thisRecord.has_Subfield('z'))
                            newTitleSubj.Add_Geographic(Remove_Trailing_Punctuation(thisRecord['z']));
                        if (thisRecord.has_Subfield('2'))
                            newTitleSubj.Authority = thisRecord['2'];
                        switch (thisRecord.Indicator2)
                        {
                            case '0':
                                newTitleSubj.Authority = "lcsh";
                                break;

                            case '1':
                                newTitleSubj.Authority = "lcshac";
                                break;

                            case '2':
                                newTitleSubj.Authority = "mesh";
                                break;

                            case '3':
                                newTitleSubj.Authority = "nal";
                                break;

                            case '5':
                                newTitleSubj.Authority = "csh";
                                break;

                            case '6':
                                newTitleSubj.Authority = "rvm";
                                break;
                        }
                        thisBibInfo.Add_Subject(newTitleSubj);
                        break;
                }
            }
        }
コード例 #3
0
        /// <summary> Add a new empty title info subject and return it  </summary>
        /// <returns>Newly built title info subject</returns>
        public Subject_Info_TitleInfo Add_Title_Subject()
        {
            if (subjects == null)
                subjects = new List<Subject_Info>();

            Subject_Info_TitleInfo returnValue = new Subject_Info_TitleInfo();
            subjects.Add(returnValue);
            return returnValue;
        }