Add records for bib entries
This commit is contained in:
		
							parent
							
								
									f5e3f92b08
								
							
						
					
					
						commit
						74541f852e
					
				@ -5,21 +5,22 @@
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:local="clr-namespace:Txt2Bib"
 | 
			
		||||
        mc:Ignorable="d"
 | 
			
		||||
        Title="MainWindow" Height="900" Width="800">
 | 
			
		||||
    <Grid Background="#FF38383E">
 | 
			
		||||
        <TextBox x:Name="DropArea" HorizontalAlignment="Left" Margin="48,82,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="431" Height="295" PreviewDragEnter="DropArea_PreviewDragEnter" PreviewDragOver="DropArea_PreviewDragOver" Drop="DropArea_Drop"/>
 | 
			
		||||
        <TextBox x:Name="Debug" HorizontalAlignment="Left" Margin="48,422,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="710" Height="429" RenderTransformOrigin="0.449,1.525"/>
 | 
			
		||||
        <Label Content="Txt2Bib" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="DejaVu Sans Light" FontSize="28"/>
 | 
			
		||||
        <Button x:Name="GoBtn" Content="Genera" HorizontalAlignment="Left" Margin="594,160,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Height="83" Width="131" Click="GoBtn_Click" BorderBrush="{x:Null}" Foreground="White" Background="#FF474671" FontFamily="Cascadia Code" FontSize="16">
 | 
			
		||||
        Title="MainWindow" Height="718" Width="800">
 | 
			
		||||
    <Grid Background="#FF38383E" Margin="0,0,0,-16">
 | 
			
		||||
        <TextBox x:Name="DropArea" Text="Trascinare qui i file txt da convertire" ToolTip="Trascinare qui i file txt da convertire" HorizontalAlignment="Left" Margin="48,82,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="526" Height="437" PreviewDragEnter="DropArea_PreviewDragEnter" PreviewDragOver="DropArea_PreviewDragOver" Drop="DropArea_Drop"/>
 | 
			
		||||
        <TextBox x:Name="Debug" IsEnabled="False" HorizontalAlignment="Center" Margin="0,572,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="710" Height="72" RenderTransformOrigin="0.449,1.525"/>
 | 
			
		||||
        <Label Content="Txt2Bib" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Eras ITC" FontSize="28"/>
 | 
			
		||||
        <Button x:Name="GoBtn" Cursor="Hand" Content="Genera" HorizontalAlignment="Left" Margin="628,244,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Height="68" Width="127" Click="GoBtn_Click" BorderBrush="{x:Null}" Foreground="White" Background="#FF474671" FontFamily="Cascadia Code" FontSize="16">
 | 
			
		||||
            <Button.RenderTransform>
 | 
			
		||||
                <TransformGroup>
 | 
			
		||||
                    <ScaleTransform/>
 | 
			
		||||
                    <SkewTransform/>
 | 
			
		||||
                    <RotateTransform Angle="-0.415"/>
 | 
			
		||||
                    <RotateTransform/>
 | 
			
		||||
                    <TranslateTransform/>
 | 
			
		||||
                </TransformGroup>
 | 
			
		||||
            </Button.RenderTransform>
 | 
			
		||||
        </Button>
 | 
			
		||||
        <Label Content="Output" HorizontalAlignment="Left" Margin="47,545,0,0" VerticalAlignment="Top" Foreground="White"/>
 | 
			
		||||
 | 
			
		||||
    </Grid>
 | 
			
		||||
</Window>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										29
									
								
								Records.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								Records.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace Txt2Bib.Records
 | 
			
		||||
{
 | 
			
		||||
    public interface IBib { }
 | 
			
		||||
    public record class ArticleBib : IBib
 | 
			
		||||
    {
 | 
			
		||||
        public string Type { get; init; } = "article";
 | 
			
		||||
        public string[] Author { get; init; } = { "" };
 | 
			
		||||
        public string Title { get; init; } = "";
 | 
			
		||||
        public string Journal { get; init; } = "";
 | 
			
		||||
        public ushort Year { get; init; } = 1950;
 | 
			
		||||
        public ushort Volume { get; init; } = 1;
 | 
			
		||||
        public byte Issue { get; init; } = 1;
 | 
			
		||||
        public ushort FirstPage { get; init; } = 1;
 | 
			
		||||
        public ushort LastPage { get; init; } = 1;
 | 
			
		||||
 | 
			
		||||
        public override string ToString()
 | 
			
		||||
        {
 | 
			
		||||
            return $"@{Type}\\{{{Author[0][..5]}_{Year}," +
 | 
			
		||||
                $"\ttitle = \"{Title}\"," +
 | 
			
		||||
                $"\tjournal = \"{Journal}\"," +
 | 
			
		||||
                $"\tyear = \"{Year}\"," +
 | 
			
		||||
                $"\tvolume = \"{Volume}\"," +
 | 
			
		||||
                $"\tnumber = \"{Issue}\"," +
 | 
			
		||||
                $"\tpages = \"{FirstPage}--{LastPage}\",";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										50
									
								
								Text2Bib.cs
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								Text2Bib.cs
									
									
									
									
									
								
							@ -6,11 +6,25 @@ using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Windows.Controls.Primitives;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using Txt2Bib.Records;
 | 
			
		||||
using System.ComponentModel.DataAnnotations;
 | 
			
		||||
 | 
			
		||||
namespace Txt2Bib
 | 
			
		||||
{
 | 
			
		||||
    internal class Text2Bib
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Dictionary<string, string> _citTypes = new()
 | 
			
		||||
        {
 | 
			
		||||
            { "J" , "article"},
 | 
			
		||||
            { "B", "book" },
 | 
			
		||||
            { "P", "conference" },
 | 
			
		||||
            { "C" , "inbook" }
 | 
			
		||||
        };
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Generate single .bib file from input text files
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="filenames"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public string Generate(string filenames)
 | 
			
		||||
        {
 | 
			
		||||
            var paths = filenames.Trim().Split('\n');
 | 
			
		||||
@ -23,24 +37,36 @@ namespace Txt2Bib
 | 
			
		||||
                byte[] contentBytes = File.ReadAllBytes(path);
 | 
			
		||||
 | 
			
		||||
                result += Encoding.Latin1.GetString(contentBytes);
 | 
			
		||||
                // How to determine actual encoding??
 | 
			
		||||
                /*
 | 
			
		||||
                result += reader.CurrentEncoding.CodePage switch
 | 
			
		||||
                {
 | 
			
		||||
                    65001 => Encoding.UTF8.GetString(contentBytes),
 | 
			
		||||
                    _ => Encoding.Latin1.GetString(contentBytes)
 | 
			
		||||
                }; 
 | 
			
		||||
                */
 | 
			
		||||
                
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //TODO process entry
 | 
			
		||||
            foreach (string item in result.Split('%'))
 | 
			
		||||
            var entries = result.Split('%').ToList<string>().Select(entry =>
 | 
			
		||||
            {
 | 
			
		||||
                output += item;
 | 
			
		||||
                return Process(entry);
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            foreach (var entry in entries)
 | 
			
		||||
            {
 | 
			
		||||
                output += entries;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return output;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private IBib Process(string entryFromTxt)
 | 
			
		||||
        {
 | 
			
		||||
            return new ArticleBib();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// TODO: How to determine correct encoding of text file??
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="reader">The stream reader for the file</param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        private Encoding GuessEncoding(StreamReader reader)
 | 
			
		||||
        {
 | 
			
		||||
            var cp = "UTF-8";
 | 
			
		||||
            return Encoding.GetEncoding(cp);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user