Personal library classification

book (Chinese)

Creating directories: approach #2

Copy the MediaWiki raw text from https://zh.wikipedia.org/wiki/Category:%E4%B8%AD%E5%9B%BD%E5%9B%BE%E4%B9%A6%E9%A6%86%E5%9B%BE%E4%B9%A6%E5%88%86%E7%B1%BB%E6%B3%95 to a Markdown file and edit the bullet list syntax:

$file="/Volumes/library2/DataSpace-Library-2/reference/standard/中国图书馆分类法（第5版）.md";

RightComposition[
Import[#,"Text"]&,
StringSplit[#,"\n"]&,
Cases[#,_String?(StringMatchQ[#,RegularExpression["^###.*"]]&)]&,
StringReplace[StringTrim@StringReplace[#,RegularExpression["^###(.*)"]-> "$1"]," "-> "_"]&/@#&,
Sort,
Rest,
With[
{dir=FileNameJoin[{"","Volumes","LIBRARY3","DataSpace-Library-Library3-main","book_(Chinese)",#}]},
If[!DirectoryQ[dir],CreateDirectory[dir]]
]&/@#&
][$file]

RightComposition[
Import[#,"Text"]&,
StringSplit[#,"\n"]&,
Cases[#,_String?(StringMatchQ[#,RegularExpression["^\\* .*"]]&)]&,
StringReplace[StringTrim@StringReplace[#,RegularExpression["^\\* (.*)"]-> "$1"]," "-> "_"]&/@#&,
Sort,
DeleteCases[#,_String?(StringMatchQ[#,RegularExpression["^\\-.*"]]&)]&,
#[[16;;]]&,
With[
{init=Characters[#][[1]]},
With[
{dir=FileNameTake[FileNames[init<>"*",{FileNameJoin[{"","Volumes","LIBRARY3","DataSpace-Library-Library3-main","book_(Chinese)"}]}][[1]],-1]},
CreateDirectory[FileNameJoin[{"","Volumes","LIBRARY3","DataSpace-Library-Library3-main","book_(Chinese)",dir,#}]]
]
]&/@#&
][$file]

SystemOpen["/Users/meng/Volumes/LIBRARY3/DataSpace-Library-Library3-main/book_(Chinese)/A_哲学、宗教"]

?CreateDirectory

Creating directories: approach #1

RightComposition[
StringSplit[#,"*"]&,
StringReplace[#,RegularExpression["\\[\\[.*\\|(.*)\\]\\]"]:>"$1"]&,
StringTrim/@#&,
StringSplit/@#&,
StringRiffle[#,"_"]&/@#&,
InputForm
][$rawString["中国图书馆分类法（第五版）"]]

(*Cases[#,XMLElement[tag_,{},{name_String?(StringMatchQ[#,RegularExpression[“A[0-9]{1,3}+(.*)”]]&)}]:> {tag,name},Infinity]&*)

Table[
RightComposition[
URLBuild[{"https://zh.wikipedia.org","wiki","中国图书馆分类法_"<>"("<>#<>")"}]&,
Import[#,"XMLObject"]&,
Cases[#,XMLElement[tag_,{},{name_String?(StringMatchQ[#,RegularExpression[initial<>"[0-9]{1,3}+(.*)"]]&)}|name:{_String?(StringMatchQ[#,RegularExpression[initial<>"[0-9]{1,3}.*"]]&),__}]:> {tag,name},Infinity]&,
(*#[[All,1]]&,
Tally*)
#[[All,2]]&,
Replace[#,args:{___,XMLElement["a",__],___}:> StringJoin@@Replace[args,XMLElement["a",_,{str_String}]:> str,{1}]]&/@#&,
StringRiffle[StringSplit[#],"_"]&/@#&,
StringReplace[#,"/"-> "_OR_"]&/@#&
][initial],
{initial,CharacterRange["A","Z"]//Evaluate}
];

Replace[#,args:{___,XMLElement["a",__],___}:> StringJoin@@Replace[args,XMLElement["a",_,{str_String}]:> str,{1}]]&/@#&,
StringRiffle[StringSplit[#],"_"]&/@#&,
StringReplace[#,"/"-> "_OR_"]&/@#&

Table[
RightComposition[
URLBuild[{"https://zh.wikipedia.org","wiki","中国图书馆分类法_"<>"("<>#<>")"}]&,
Import[#,"XMLObject"]&,
Cases[#,XMLElement[tag_,{},{name_String?(StringMatchQ[#,RegularExpression[initial<>"[0-9]{1,3}+(.*)"]]&)}|name:{_String?(StringMatchQ[#,RegularExpression[initial<>"[0-9]{1,3}.*"]]&),__}]:> {tag,name},Infinity]&,
(*#[[All,1]]&,
Tally*)
#[[All,2]]&,
Replace[#,args:{___,XMLElement["a",__],___}:> (*StringJoin@@*)Replace[args,XMLElement["a",_,{str_String}]:> str,{1}]]&/@#&
][initial],
{initial,{"Z"}}
]

Out[51]//Most

References

source: https://zh.wikipedia.org/zh-cn/%E4%B8%AD%E5%9B%BD%E5%9B%BE%E4%B9%A6%E9%A6%86%E5%88%86%E7%B1%BB%E6%B3%95

raw string

$rawString["中国图书馆分类法（第五版）"]="*[[中国图书馆分类法 (A)|A 马克思列宁主义、毛泽东思想、邓小平理论]]  
*[[中国图书馆分类法 (B)|B 哲学、宗教]]  
*[[中国图书馆分类法 (C)|C 社会科学总论]] 
*[[中国图书馆分类法 (D)|D 政治、法律]] 
*[[中国图书馆分类法 (E)|E 军事]] 
*[[中国图书馆分类法 (F)|F 经济]] 
*[[中国图书馆分类法 (G)|G 文化、科学、教育、体育]] 
*[[中国图书馆分类法 (H)|H 语言、文字]] 
*[[中国图书馆分类法 (I)|I 文学]] 
*[[中国图书馆分类法 (J)|J 艺术]] 
*[[中国图书馆分类法 (K)|K 历史、地理]]  
*[[中国图书馆分类法 (N)|N 自然科学总论]] 
*[[中国图书馆分类法 (O)|O 数理科学和化学]]
*[[中国图书馆分类法 (P)|P 天文学、地球科学]]  
*[[中国图书馆分类法 (Q)|Q 生物科学]]
*[[中国图书馆分类法 (R)|R 医药、卫生]] 
*[[中国图书馆分类法 (S)|S 农业科学]] 
*[[中国图书馆分类法 (T)|T 工业技术]] 
*[[中国图书馆分类法 (U)|U 交通运输]] 
*[[中国图书馆分类法 (V)|V 航空、航天]] 
*[[中国图书馆分类法 (X)|X 环境科学、安全科学]] 
*[[中国图书馆分类法 (Z)|Z 综合性图书]]";

book (non-Chinese)

Creating directories: approach #1

Copy the MediaWiki raw text from https://en.wikipedia.org/wiki/Library_of_Congress_Classification to a Markdown file and edit the bullet list syntax:

$file="/Volumes/library2/DataSpace-Library-2/reference/standard/Library_of_Congress_Classification_2020.md";

RightComposition[
Import[#,"Text"]&,
StringSplit[#,"\n"]&,
Cases[#,_String?(StringMatchQ[#,RegularExpression["^###.*"]]&)]&,
StringReplace[StringTrim@StringReplace[#,RegularExpression["^###(.*)"]->"$1"]," "->"_"]&/@#&,
StringReplace[#,{"Class_"->"","_–_"->"_"}]&/@#&,
Sort,
With[{dir=FileNameJoin[{"","Volumes","LIBRARY3","DataSpace-Library-Library3-main","book_(non-Chinese)",#}]},If[!DirectoryQ[dir],CreateDirectory[dir]]]&/@#&
][$file]

RightComposition[
Import[#,"Text"]&,
StringSplit[#,"\n"]&,
Cases[#,_String?(StringMatchQ[#,RegularExpression["^\\* Subclass .*"]]&)]&,
StringReplace[StringTrim@StringReplace[#,RegularExpression["^\\* Subclass (.*)"]-> "$1"]," "-> "_"]&/@#&,
StringReplace[#,{"_–_"->"-"}]&/@#&,
Sort,
#[[;;]]&,
With[
{init=Characters[#][[1]]},
With[
{dir=FileNameTake[FileNames[init<>"*",{FileNameJoin[{"","Volumes","LIBRARY3","DataSpace-Library-Library3-main","book_(non-Chinese)"}]}][[1]],-1]},
Module[{subdir=FileNameJoin[{"","Volumes","LIBRARY3","DataSpace-Library-Library3-main","book_(non-Chinese)",dir,If[StringLength[#]>250,StringTake[#,243]<>"_…",#]}]},
If[!DirectoryQ[subdir],CreateDirectory[subdir],Print[subdir]]
]
]
]&/@#&
][$file]