1 | #Region "Microsoft.VisualBasic::d79509578cdf3ec429654533e34cb55a, Microsoft.VisualBasic.Core\ComponentModel\DataSource\SchemaMaps\PropertyValue.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 | ' Interface IPropertyValue |
35 | ' |
36 | ' Properties: [Property] |
37 | ' |
38 | ' Class PropertyValue |
39 | ' |
40 | ' Properties: [Property], Key, Value |
41 | ' |
42 | ' Function: ImportsLines, ImportsTsv, ToString |
43 | ' |
44 | ' |
45 | ' /********************************************************************************/ |
46 | |
47 | #End Region |
48 | |
49 | Imports System.Runtime.CompilerServices |
50 | Imports System.Xml.Serialization |
51 | Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic |
52 | Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel.Repository |
53 | Imports Microsoft.VisualBasic.Language |
54 | Imports Microsoft.VisualBasic.Serialization.JSON |
55 | Imports Microsoft.VisualBasic.Text |
56 | |
57 | Namespace ComponentModel.DataSourceModel.SchemaMaps |
58 | |
59 | Public Interface IPropertyValue : Inherits INamedValue, Value(Of String).IValueOf |
60 | Property [Property] As String |
61 | End Interface |
62 | |
63 | ''' <summary> |
64 | ''' 用于读写tsv/XML文件格式的键值对数据 |
65 | ''' </summary> |
66 | Public Class PropertyValue |
67 | Implements INamedValue, IPropertyValue |
68 | |
69 | ''' <summary> |
70 | ''' ID |
71 | ''' </summary> |
72 | ''' <returns></returns> |
73 | <XmlAttribute> Public Property Key As String Implements IKeyedEntity(Of String).Key |
74 | ''' <summary> |
75 | ''' Property Name |
76 | ''' </summary> |
77 | ''' <returns></returns> |
78 | <XmlAttribute> Public Property [Property] As String Implements IPropertyValue.Property |
79 | ''' <summary> |
80 | ''' Value text |
81 | ''' </summary> |
82 | ''' <returns></returns> |
83 | <XmlText> Public Property Value As String Implements IPropertyValue.Value |
84 | |
85 | Public Overrides Function ToString() As String |
86 | Return Me.GetJson |
87 | End Function |
88 | |
89 | ''' <summary> |
90 | ''' Imports the tsv file like: |
91 | ''' |
92 | ''' ``` |
93 | ''' <ID><tab><PropertyName><tab><Value> |
94 | ''' ``` |
95 | ''' </summary> |
96 | ''' <param name="path$"></param> |
97 | ''' <returns></returns> |
98 | Public Shared Function ImportsTsv(path$, Optional header As Boolean = True) As PropertyValue() |
99 | Dim lines$() = path.ReadAllLines |
100 | |
101 | If header Then |
102 | lines = lines.Skip(1).ToArray |
103 | End If |
104 | |
105 | Return ImportsLines( |
106 | data:=lines, |
107 | delimiter:=ASCII.TAB) |
108 | End Function |
109 | |
110 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
111 | Public Shared Function ImportsLines(data As IEnumerable(Of String), Optional delimiter As Char = ASCII.TAB) As PropertyValue() |
112 | Return data _ |
113 | .Select(Function(t) t.Split(delimiter)) _ |
114 | .Select(Function(row) New PropertyValue With { |
115 | .Key = row(0), |
116 | .Property = row(1), |
117 | .Value = row(2) |
118 | }).ToArray |
119 | End Function |
120 | End Class |
121 | End Namespace |