Handle book chapter
This commit is contained in:
parent
d2dd282307
commit
4e7fd92a13
65
Records.cs
65
Records.cs
@ -153,7 +153,6 @@ namespace Txt2Bib.Records
|
|||||||
{
|
{
|
||||||
public string Type { get; init; } = "inproceedings";
|
public string Type { get; init; } = "inproceedings";
|
||||||
public string[] Author { get; set; } = Array.Empty<string>();
|
public string[] Author { get; set; } = Array.Empty<string>();
|
||||||
public string[] Editor { get; set; } = Array.Empty<string>();
|
|
||||||
public string Title { get; set; } = "";
|
public string Title { get; set; } = "";
|
||||||
public string BookTitle { get; set; } = "";
|
public string BookTitle { get; set; } = "";
|
||||||
public ushort Year { get; set; } = 1950;
|
public ushort Year { get; set; } = 1950;
|
||||||
@ -209,4 +208,68 @@ namespace Txt2Bib.Records
|
|||||||
"}\n";
|
"}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record class Chapter : ItemType, IBib
|
||||||
|
{
|
||||||
|
public string Type { get; init; } = "incollection";
|
||||||
|
public string[] Author { get; set; } = Array.Empty<string>();
|
||||||
|
public string[] Editor { get; set; } = Array.Empty<string>();
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
|
||||||
|
Year = ushort.Parse(entryLines[2]);
|
||||||
|
Title = entryLines[3];
|
||||||
|
Editor = entryLines[4].Replace("(eds.)", "").Split(',').Select(a => Rearrange(a)).ToArray();
|
||||||
|
BookTitle = entryLines[5];
|
||||||
|
Address = entryLines[6] != String.Empty ? entryLines[6] : Address;
|
||||||
|
Publisher = entryLines[7];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FirstPage = ushort.Parse(entryLines[8].Split('-')[0]);
|
||||||
|
LastPage = ushort.Parse(entryLines[8].Split('-')[1].TrimEnd('.'));
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entryLines.Length > 9)
|
||||||
|
{
|
||||||
|
if (IsDoi(entryLines[9])) Doi = entryLines[9];
|
||||||
|
else Url = entryLines[9];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string label = Author[0][..5].Replace(". ", "");
|
||||||
|
string authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n";
|
||||||
|
string edsString = $"\teditor = \"{string.Join(" and ", Editor)}\",\n";
|
||||||
|
|
||||||
|
return $"@{Type}{{{label}_{Year},\n" +
|
||||||
|
authString +
|
||||||
|
edsString +
|
||||||
|
$"\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";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ namespace Txt2Bib
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Text2Bib
|
public class Text2Bib
|
||||||
{
|
{
|
||||||
private string[] _citTypes = { "J", "B", "C", "P", "I" };
|
private string[] _citTypes = { "J", "B", "C", "P" };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate single .bib file from input text files
|
/// Generate single .bib file from input text files
|
||||||
@ -84,7 +84,7 @@ namespace Txt2Bib
|
|||||||
{
|
{
|
||||||
"J" => new Article().Convert(lines),
|
"J" => new Article().Convert(lines),
|
||||||
"B" => new Book().Convert(lines),
|
"B" => new Book().Convert(lines),
|
||||||
//"C" => new ChapterBib(),
|
"C" => new Chapter().Convert(lines),
|
||||||
"P" => new Proceedings().Convert(lines),
|
"P" => new Proceedings().Convert(lines),
|
||||||
_ => ""
|
_ => ""
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user