diff --git a/Records.cs b/Records.cs index 70485b5..264dfcb 100644 --- a/Records.cs +++ b/Records.cs @@ -56,7 +56,7 @@ namespace Txt2Bib.Records try { FirstPage = ushort.Parse(entryLines[6].Split('-')[0]); - LastPage = ushort.Parse(entryLines[6].Split('-')[1]); + LastPage = ushort.Parse(entryLines[6].Split('-')[1].TrimEnd('.')); } catch (Exception) { @@ -158,4 +158,71 @@ namespace Txt2Bib.Records "}\n"; } } + + public record class Proceedings : ItemType, IBib + { + public string Type { get; init; } = "inproceedings"; + public string[] Author { get; set; } = Array.Empty(); + public string[] Editor { get; set; } = Array.Empty(); + public string Title { get; set; } = ""; + public string BookTitle { get; set; } = ""; + public ushort Year { get; set; } = 1950; + public string Publisher { get; set; } = ""; + public string Address { get; set; } = ""; + public ushort FirstPage { get; set; } = 1; + public ushort LastPage { get; set; } = 1; + public string Url { get; set; } = ""; + public string Doi { get; set; } = ""; + + public string Convert(string[] entryLines) + { + var rearrange = (string a) => + { + a = a.Trim(); + var s = a.Split(' '); + return $"{s[1]} {s[0]}"; + }; + Author = entryLines[1].Split(',').Select(a => rearrange(a)).ToArray(); + Year = ushort.Parse(entryLines[2]); + Title = entryLines[3]; + BookTitle = entryLines[4]; + Address = entryLines[5] != String.Empty ? entryLines[5] : Address; + Publisher = entryLines[6]; + try + { + FirstPage = ushort.Parse(entryLines[7].Split('-')[0]); + LastPage = ushort.Parse(entryLines[7].Split('-')[1].TrimEnd('.')); + } + catch (Exception) + { + throw; + } + + if (entryLines.Length > 8 ) + { + if (IsDoi(entryLines[8])) Doi = entryLines[8]; + else Url = entryLines[8]; + } + + return ToString(); + } + + public override string ToString() + { + string label = Author[0][..5].Replace(". ", ""); + string authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n"; + + return $"@{Type}{{{label}_{Year},\n" + + authString + + $"\ttitle = {{{Title}}},\n" + + $"\tbooktitle = {{{BookTitle}}},\n" + + $"\tpublisher = \"{Publisher}\",\n" + + $"\taddress = \"{Address}\",\n" + + $"\tyear = \"{Year}\",\n" + + $"\tpages = \"{FirstPage}--{LastPage}\",\n" + + $"\turl = \"{Url}\",\n" + + $"\tdoi = \"{Doi}\",\n" + + "}\n"; + } + } } \ No newline at end of file diff --git a/Text2Bib.cs b/Text2Bib.cs index a089b6c..9d50eb5 100644 --- a/Text2Bib.cs +++ b/Text2Bib.cs @@ -82,10 +82,10 @@ namespace Txt2Bib { citation = type switch { - "J" => (new Article()).Convert(lines), + "J" => new Article().Convert(lines), "B" => new Book().Convert(lines), //"C" => new ChapterBib(), - //"P" => new ConferenceBib(), + "P" => new Proceedings().Convert(lines), _ => "" }; } diff --git a/Txt2Bib.csproj b/Txt2Bib.csproj index c7ae09c..bc2cd8b 100644 --- a/Txt2Bib.csproj +++ b/Txt2Bib.csproj @@ -5,7 +5,7 @@ net6.0-windows enable true - 0.1.1 + 0.1.2