Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 43942125c9 | |||
| 82c2bc6ce2 | |||
| 4e7fd92a13 | |||
| d2dd282307 | |||
| 96dff46c14 |
@@ -55,7 +55,7 @@ namespace Txt2Bib
|
|||||||
if (dataObject.ContainsFileDropList())
|
if (dataObject.ContainsFileDropList())
|
||||||
{
|
{
|
||||||
// Clear values
|
// Clear values
|
||||||
DropArea.Text = string.Empty;
|
if (DropArea.Text == InitialDropText) DropArea.Text = string.Empty;
|
||||||
|
|
||||||
// Process file names
|
// Process file names
|
||||||
var fileNames = dataObject.GetFileDropList();
|
var fileNames = dataObject.GetFileDropList();
|
||||||
@@ -65,7 +65,7 @@ namespace Txt2Bib
|
|||||||
bd.Append(fileName + "\n");
|
bd.Append(fileName + "\n");
|
||||||
}
|
}
|
||||||
// Set text
|
// Set text
|
||||||
DropArea.Text = bd.ToString();
|
DropArea.Text += bd.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +89,7 @@ namespace Txt2Bib
|
|||||||
private void GoBtn_Click(object sender, RoutedEventArgs e)
|
private void GoBtn_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Execute();
|
Execute();
|
||||||
|
MessageBox.Show("File BibTeX generato correttamente.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyDebug_Click(object sender, RoutedEventArgs e)
|
private void CopyDebug_Click(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
156
Records.cs
156
Records.cs
@@ -1,17 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.CodeDom;
|
|
||||||
using System.Configuration;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows.Media.Converters;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
|
|
||||||
namespace Txt2Bib.Records
|
namespace Txt2Bib.Records
|
||||||
{
|
{
|
||||||
public interface IBib {
|
public interface IBib {
|
||||||
public string Convert(string[] entryLines);
|
public string Convert(string[] entryLines);
|
||||||
public string ToString();
|
public string ToString();
|
||||||
}
|
};
|
||||||
|
|
||||||
public abstract record ItemType
|
public abstract record ItemType
|
||||||
{
|
{
|
||||||
@@ -19,6 +15,12 @@ namespace Txt2Bib.Records
|
|||||||
{
|
{
|
||||||
return url.Contains("doi");
|
return url.Contains("doi");
|
||||||
}
|
}
|
||||||
|
protected static string Rearrange(string a)
|
||||||
|
{
|
||||||
|
a = a.Trim();
|
||||||
|
var s = a.Split(' ');
|
||||||
|
return $"{s[1]} {s[0]}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record class Article : ItemType, IBib
|
public record class Article : ItemType, IBib
|
||||||
@@ -37,16 +39,10 @@ namespace Txt2Bib.Records
|
|||||||
|
|
||||||
public string Convert(string[] entryLines)
|
public string Convert(string[] entryLines)
|
||||||
{
|
{
|
||||||
var rearrange = (string a) =>
|
|
||||||
{
|
|
||||||
a = a.Trim();
|
|
||||||
var s = a.Split(' ');
|
|
||||||
return $"{s[1]} {s[0]}";
|
|
||||||
};
|
|
||||||
var checkVol = (string v) =>
|
var checkVol = (string v) =>
|
||||||
v.Split(',').Length == 2 ? v.Split(',')[0].Trim() : v.Trim();
|
v.Split(',').Length == 2 ? v.Split(',')[0].Trim() : v.Trim();
|
||||||
|
|
||||||
Author = entryLines[1].Split(',').Select(a => rearrange(a)).ToArray();
|
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
|
||||||
Year = ushort.Parse(entryLines[2]);
|
Year = ushort.Parse(entryLines[2]);
|
||||||
Title = entryLines[3];
|
Title = entryLines[3];
|
||||||
Journal = entryLines[4];
|
Journal = entryLines[4];
|
||||||
@@ -56,7 +52,7 @@ namespace Txt2Bib.Records
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
FirstPage = ushort.Parse(entryLines[6].Split('-')[0]);
|
FirstPage = ushort.Parse(entryLines[6].Split('-')[0]);
|
||||||
LastPage = ushort.Parse(entryLines[6].Split('-')[1]);
|
LastPage = ushort.Parse(entryLines[6].Split('-')[1].TrimEnd('.'));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -102,20 +98,14 @@ namespace Txt2Bib.Records
|
|||||||
|
|
||||||
public string Convert(string[] entryLines)
|
public string Convert(string[] entryLines)
|
||||||
{
|
{
|
||||||
var rearrange = (string a) =>
|
|
||||||
{
|
|
||||||
a = a.Trim();
|
|
||||||
var s = a.Split(' ');
|
|
||||||
return $"{s[1]} {s[0]}";
|
|
||||||
};
|
|
||||||
var auths = entryLines[1];
|
var auths = entryLines[1];
|
||||||
if (auths.Contains("eds"))
|
if (auths.Contains("eds"))
|
||||||
{
|
{
|
||||||
Editor = auths.Replace("(eds.)", "").Split(',').Select(a => rearrange(a)).ToArray();
|
Editor = auths.Replace("(eds.)", "").Split(',').Select(a => Rearrange(a)).ToArray();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Author = auths.Split(',').Select(a => rearrange(a)).ToArray();
|
Author = auths.Split(',').Select(a => Rearrange(a)).ToArray();
|
||||||
}
|
}
|
||||||
Year = ushort.Parse(entryLines[2]);
|
Year = ushort.Parse(entryLines[2]);
|
||||||
Title = entryLines[3];
|
Title = entryLines[3];
|
||||||
@@ -158,4 +148,128 @@ namespace Txt2Bib.Records
|
|||||||
"}\n";
|
"}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record class Proceedings : ItemType, IBib
|
||||||
|
{
|
||||||
|
public string Type { get; init; } = "inproceedings";
|
||||||
|
public string[] Author { 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];
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 readonly string[] _citTypes = { "J", "B", "C", "P" };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate single .bib file from input text files
|
/// Generate single .bib file from input text files
|
||||||
@@ -82,10 +82,10 @@ namespace Txt2Bib
|
|||||||
{
|
{
|
||||||
citation = type switch
|
citation = type switch
|
||||||
{
|
{
|
||||||
"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 ConferenceBib(),
|
"P" => new Proceedings().Convert(lines),
|
||||||
_ => ""
|
_ => ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<Version>0.1.1</Version>
|
<Version>0.1.5</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user