| 1 | #Region "Microsoft.VisualBasic::7832f705d2d954f961650e5493d73356, Microsoft.VisualBasic.Core\Scripting\MetaData\Cite.vb" |
| 2 | |
| 3 | ' Author: |
| 4 | ' |
| 5 | ' asuka (amethyst.asuka@gcmodeller.org) |
| 6 | ' xie (genetics@smrucc.org) |
| 7 | ' xieguigang (xie.guigang@live.com) |
| 8 | ' |
| 9 | ' Copyright (c) 2018 GPL3 Licensed |
| 10 | ' |
| 11 | ' |
| 12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
| 13 | ' |
| 14 | ' |
| 15 | ' This program is free software: you can redistribute it and/or modify |
| 16 | ' it under the terms of the GNU General Public License as published by |
| 17 | ' the Free Software Foundation, either version 3 of the License, or |
| 18 | ' (at your option) any later version. |
| 19 | ' |
| 20 | ' This program is distributed in the hope that it will be useful, |
| 21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | ' GNU General Public License for more details. |
| 24 | ' |
| 25 | ' You should have received a copy of the GNU General Public License |
| 26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | |
| 28 | |
| 29 | |
| 30 | ' /********************************************************************************/ |
| 31 | |
| 32 | ' Summaries: |
| 33 | |
| 34 | ' Class Cite |
| 35 | ' |
| 36 | ' Properties: Abstract, AuthorAddress, Authors, DOI, ISSN |
| 37 | ' Issue, Journal, Keywords, Notes, Pages |
| 38 | ' PubMed, StartPage, Title, URL, Volume |
| 39 | ' Year |
| 40 | ' |
| 41 | ' Constructor: (+2 Overloads) Sub New |
| 42 | ' Function: __formatAbstractPreview, (+2 Overloads) GetCiteList, HTML, ToString |
| 43 | ' |
| 44 | ' |
| 45 | ' /********************************************************************************/ |
| 46 | |
| 47 | #End Region |
| 48 | |
| 49 | Imports System.Reflection |
| 50 | Imports System.Text |
| 51 | Imports System.Text.RegularExpressions |
| 52 | Imports Microsoft.VisualBasic.Linq.Extensions |
| 53 | |
| 54 | Namespace Scripting.MetaData |
| 55 | |
| 56 | ''' <summary> |
| 57 | ''' EndNote tags |
| 58 | ''' </summary> |
| 59 | <AttributeUsage(AttributeTargets.Module Or AttributeTargets.Method Or AttributeTargets.Class, AllowMultiple:=True, Inherited:=True)> |
| 60 | Public Class Cite : Inherits Attribute |
| 61 | |
| 62 | ''' <summary> |
| 63 | ''' author(eMail);author(eMail) |
| 64 | ''' </summary> |
| 65 | ''' <returns></returns> |
| 66 | Public Property Authors As String |
| 67 | Public Property Year As Integer |
| 68 | Public Property Title As String |
| 69 | Public Property Journal As String |
| 70 | Public Property Volume As Integer |
| 71 | Public Property Issue As String |
| 72 | Public Property Pages As String |
| 73 | Public Property StartPage As Integer |
| 74 | ''' <summary> |
| 75 | ''' ISSN_1; ISSN_2; ISSN_3 |
| 76 | ''' </summary> |
| 77 | ''' <returns></returns> |
| 78 | Public Property ISSN As String |
| 79 | Public Property DOI As String |
| 80 | Public Property PubMed As Integer |
| 81 | Public Property Keywords As String |
| 82 | ''' <summary> |
| 83 | ''' 文章的摘要,可以使用<p>或者<br/>来进行分段 |
| 84 | ''' </summary> |
| 85 | ''' <returns></returns> |
| 86 | Public Property Abstract As String |
| 87 | Public Property Notes As String |
| 88 | Public Property URL As String |
| 89 | Public Property AuthorAddress As String |
| 90 | |
| 91 | ''' <summary> |
| 92 | ''' %x 是文章的摘要,可以使用<p>或者<br/>来进行分段 |
| 93 | ''' </summary> |
| 94 | ''' <param name="EndNoteImports"></param> |
| 95 | ''' <remarks> |
| 96 | ''' %A Griffiths-Jones, Sam |
| 97 | ''' %A Bateman, Alex |
| 98 | ''' %A Marshall, Mhairi |
| 99 | ''' %A Khanna, Ajay |
| 100 | ''' %A Eddy, Sean R. |
| 101 | ''' %T Rfam: an RNA family database |
| 102 | ''' %0 Journal Article |
| 103 | ''' %D 2003 |
| 104 | ''' %8 January 1, 2003 |
| 105 | ''' %J Nucleic Acids Research |
| 106 | ''' %P 439-441 |
| 107 | ''' %R 10.1093/nar/gkg006 |
| 108 | ''' %V 31 |
| 109 | ''' %N 1 |
| 110 | ''' %U http://nar.oxfordjournals.org/content/31/1/439.abstract |
| 111 | ''' %X Rfam Is a collection of multiple sequence alignments And covariance models representing non-coding RNA families. Rfam Is available on the web in the UK at http://www.sanger.ac.uk/Software/Rfam/ And in the US at http://rfam.wustl.edu/. These websites allow the user to search a query sequence against a library of covariance models, And view multiple sequence alignments And family annotation. The database can also be downloaded in flatfile form And searched locally using the INFERNAL package (http://infernal.wustl.edu/). The first release of Rfam (1.0) contains 25 families, which annotate over 50 000 non-coding RNA genes in the taxonomic divisions of the EMBL nucleotide database. |
| 112 | ''' </remarks> |
| 113 | Sub New(EndNoteImports As String) |
| 114 | Dim lines As String() = EndNoteImports.LineTokens |
| 115 | Dim dict As Dictionary(Of String, String()) = (From line As String In lines |
| 116 | Where Not String.IsNullOrWhiteSpace(line) |
| 117 | Let flag As String = line.Split.First |
| 118 | Let value As String = Mid(line, Len(flag) + 1).Trim |
| 119 | Select flag, value |
| 120 | Group By flag Into Group) _ |
| 121 | .ToDictionary(Function(x) x.flag, |
| 122 | Function(x) x.Group.Select(Function(xx) xx.value).ToArray) |
| 123 | Authors = dict.TryGetValue("%A").JoinBy("; ") |
| 124 | Title = dict.TryGetValue("%T", [default]:=New String() {}).FirstOrDefault |
| 125 | DOI = dict.TryGetValue("%R", [default]:=New String() {}).FirstOrDefault |
| 126 | Year = CInt(Val(dict.TryGetValue("%D", [default]:=New String() {}).FirstOrDefault)) |
| 127 | Pages = dict.TryGetValue("%P", [default]:=New String() {}).FirstOrDefault |
| 128 | Journal = dict.TryGetValue("%J", [default]:=New String() {}).FirstOrDefault |
| 129 | Volume = CInt(Val(dict.TryGetValue("%V", [default]:=New String() {}).FirstOrDefault)) |
| 130 | URL = dict.TryGetValue("%U", [default]:=New String() {}).FirstOrDefault |
| 131 | Abstract = dict.TryGetValue("%X", [default]:=New String() {}).FirstOrDefault |
| 132 | End Sub |
| 133 | |
| 134 | Sub New() |
| 135 | End Sub |
| 136 | |
| 137 | Public Overrides Function ToString() As String |
| 138 | Return $"{Authors}, {Title}, {Journal}. {Volume} ({Issue}) ({Year}) {Pages}." |
| 139 | End Function |
| 140 | |
| 141 | Public Shared Function GetCiteList(Of T)() As Cite() |
| 142 | #If NET_40 = 0 Then |
| 143 | Dim typeDef As Type = GetType(T) |
| 144 | Dim attrs = typeDef.GetCustomAttributes(Of Cite)(inherit:=True) |
| 145 | Return attrs |
| 146 | #Else |
| 147 | Throw New NotSupportedException |
| 148 | #End If |
| 149 | End Function |
| 150 | |
| 151 | Public Shared Function GetCiteList(typeDef As Type) As Cite() |
| 152 | #If NET_40 = 0 Then |
| 153 | Dim attrs As Cite() = typeDef.GetCustomAttributes(Of Cite)(inherit:=True) |
| 154 | Return attrs |
| 155 | #Else |
| 156 | Throw New NotSupportedException |
| 157 | #End If |
| 158 | End Function |
| 159 | |
| 160 | Public Function HTML(absLen As Integer) As String |
| 161 | Dim htmlBuilder As StringBuilder = New StringBuilder(1024) |
| 162 | |
| 163 | Call htmlBuilder.Append($"<i>{Authors}</i>.({Year}). ""<strong>{Title}</strong>"", {Journal}. <strong>{Volume}</strong>({Issue}) {Pages}.") |
| 164 | Call htmlBuilder.AppendLine($"<p><pre>{Me.__formatAbstractPreview(absLen)}</pre></p>") |
| 165 | Call htmlBuilder.AppendLine("<font size=""2"">") |
| 166 | Call htmlBuilder.AppendLine($"<p><font size=""2""><strong>Keywords: </strong> <i>{Keywords}</i><br /></font></p>") |
| 167 | Call htmlBuilder.AppendLine($"<p><font size=""2""><strong>Author Contacts: </strong> {AuthorAddress}</font></p>") |
| 168 | Call htmlBuilder.AppendLine("<i>") |
| 169 | If Not String.IsNullOrEmpty(DOI) Then |
| 170 | Call htmlBuilder.AppendLine($"<li>DOI: <a href=""http://doi.org/{DOI}"">{DOI}</a></li><br />") |
| 171 | End If |
| 172 | If Not PubMed = 0 Then |
| 173 | Call htmlBuilder.AppendLine($"<li>PMC FullText: <a href=""http://www.ncbi.nlm.nih.gov/pubmed/{PubMed}"">{PubMed}</a></li>") |
| 174 | End If |
| 175 | Call htmlBuilder.AppendLine(" |
| 176 | </i> |
| 177 | </font>") |
| 178 | |
| 179 | Return htmlBuilder.ToString |
| 180 | End Function |
| 181 | |
| 182 | ''' <summary> |
| 183 | ''' 摘要可能会有空值的 |
| 184 | ''' </summary> |
| 185 | ''' <param name="absLen"></param> |
| 186 | ''' <returns></returns> |
| 187 | Private Function __formatAbstractPreview(absLen As String) As String |
| 188 | If String.IsNullOrEmpty(Abstract) Then |
| 189 | Return "" |
| 190 | End If |
| 191 | |
| 192 | Dim Tokens As String() = Regex.Split(Abstract.Replace(vbCr, "").Replace(vbLf, " ").Replace(" ", " "), "<p>", RegexOptions.IgnoreCase Or RegexOptions.Singleline) |
| 193 | Tokens = (From s As String In Tokens Select Regex.Split(s, "<br/>", RegexOptions.Singleline Or RegexOptions.IgnoreCase)).ToArray.ToVector |
| 194 | Dim sbr As StringBuilder = New StringBuilder(1024) |
| 195 | |
| 196 | For Each s As String In Tokens |
| 197 | Call StringHelpers.Parts(s, absLen, sbr) |
| 198 | Call sbr.AppendLine(" ") |
| 199 | Next |
| 200 | |
| 201 | Return sbr.ToString |
| 202 | End Function |
| 203 | End Class |
| 204 | End Namespace |