Skip to content

Commit ec8f2a7

Browse files
committed
Add FENaming
1 parent f13c47e commit ec8f2a7

File tree

3 files changed

+360
-3
lines changed

3 files changed

+360
-3
lines changed

FENaming.wl

+304
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
(* ::Package:: *)
2+
3+
BeginPackage["FrontEndNaming`"];
4+
FENamed::usage = "A named object for display in the front end";
5+
6+
7+
BeginPackage["`Package`"];
8+
9+
10+
nameBoxApply::usage="";
11+
getNamedObject::usage="";
12+
selectNamedObject::usage="";
13+
readNamedObjectContents::usage="";
14+
replaceNamedObjectContents::usage="";
15+
getNamedObjectOptions::usage="";
16+
setNamedObjectOptions::usage="";
17+
18+
19+
EndPackage[];
20+
21+
22+
Begin["`Private`"];
23+
24+
25+
feObjectPattern =
26+
_CellObject | _BoxObject | _NotebookObject |
27+
_FrontEnd`InputNotebook | _FrontEnd`EvaluationNotebook | _FrontEnd`ButtonNotebook |
28+
_FrontEnd`EvaluationCell | _FrontEnd`EvaluationBox |_FrontEnd`Self | _FrontEnd`Parent;
29+
30+
31+
FENamed//Clear
32+
33+
34+
(* Constructor DownValues *)
35+
FENamed[
36+
FENamed[expr_, objOld : feObjectPattern | Automatic : Automatic,
37+
name_String, ops : OptionsPattern[TagBox]
38+
],
39+
objNew : feObjectPattern | Automatic : Automatic,
40+
name_String,
41+
ops2 : OptionsPattern[]
42+
] := FENamed[expr, objNew, name, Flatten[{ops2, ops}]];
43+
FENamed[
44+
expr_,
45+
obj : feObjectPattern | Automatic : Automatic,
46+
ops : OptionsPattern[]
47+
] := FENamed[expr, obj, CreateUUID[], ops];
48+
49+
50+
(* FormatValues *)
51+
Format[n :
52+
FENamed[expr_, obj : feObjectPattern | Automatic : Automatic,
53+
name_String, ops : OptionsPattern[]]] :=
54+
RawBoxes@
55+
TemplateBox[
56+
{
57+
TagBox[ToBoxes[expr], name, BoxID -> name, ops],
58+
ToBoxes[obj], ToBoxes[name], ToBoxes[Flatten@{ops}]
59+
},
60+
"FENamed",
61+
DisplayFunction -> Function[#],
62+
InterpretationFunction ->
63+
Function[
64+
RowBox[{"FENamed", "[", #[[1]], ",", #2, ",", #3, "," , #4,
65+
"]"}]],
66+
Editable -> True
67+
];
68+
69+
70+
Clear[
71+
nameBoxApply,
72+
nameBoxApply,
73+
getNamedObject,
74+
selectNamedObject,
75+
readNamedObjectContents,
76+
replaceNamedObjectContents,
77+
getNamedObjectOptions,
78+
setNamedObjectOptions
79+
]
80+
81+
82+
parseRelSpec[stuff_]:=
83+
Fold
84+
85+
86+
nameBoxApply[
87+
obj : feObjectPattern | Automatic : Automatic,
88+
sibling: _Down|_Up|_Left|_Right|None : Down[1],
89+
spec : Next | Previous : Next,
90+
refOps : _?OptionQ : {},
91+
name_String,
92+
fn_,
93+
args___
94+
] :=
95+
With[{fob=Replace[obj, Automatic -> FrontEnd`InputNotebook[]]},
96+
MathLink`CallFrontEnd@
97+
fn[
98+
FE`BoxReference[
99+
FE`Evaluate@fob,
100+
{{name}},
101+
Sequence @@
102+
DeleteDuplicatesBy[First]@
103+
Flatten@{
104+
refOps,
105+
FE`BoxOffset ->
106+
{
107+
Replace[sibling,
108+
{
109+
None->Nothing,
110+
deeep_[n_]:>
111+
Replace[deeep,
112+
{
113+
Up->FE`BoxParent,
114+
Down->FE`BoxChild,
115+
Left->FE`BoxLeftSibling,
116+
Right->FE`BoxRightSibling
117+
}
118+
][n]
119+
}
120+
]
121+
},
122+
Switch[spec,
123+
First,
124+
FE`SearchStart ->
125+
"StartFromBeginning",
126+
Next,
127+
FE`SearchStart ->
128+
"StartFromBeginning"(*Sequence@@{}*),
129+
Previous,
130+
FE`SearchStart ->
131+
"StartFromBeginning"(*Sequence@@{}*)
132+
],
133+
FE`SearchStop->None,
134+
Switch[
135+
spec,
136+
First,
137+
FE`SearchDirection -> Backward,
138+
Next,
139+
FE`SearchDirection -> Forward,
140+
Previous,
141+
FE`SearchDirection -> Backward
142+
]
143+
}
144+
],
145+
args
146+
]
147+
];
148+
149+
150+
getNamedObject[
151+
obj : feObjectPattern | Automatic : Automatic,
152+
spec:Next|Previous:Next,
153+
name_String,
154+
ops:OptionsPattern[]
155+
] :=
156+
nameBoxApply[obj, spec, {ops}, name, FrontEnd`BoxReferenceBoxObject];
157+
158+
159+
selectNamedObject[
160+
obj : feObjectPattern | Automatic : Automatic,
161+
spec:Next|Previous:Next,
162+
name_String,
163+
ops:OptionsPattern[]
164+
] :=
165+
nameBoxApply[obj, spec, {ops},
166+
name,
167+
FrontEnd`BoxReferenceFind
168+
];
169+
170+
171+
readNamedObjectContents[
172+
obj : feObjectPattern | Automatic : Automatic,
173+
spec:Next|Previous:Next,
174+
name_String,
175+
ops:OptionsPattern[]
176+
] :=
177+
nameBoxApply[obj, spec, {ops},
178+
name,
179+
FrontEnd`BoxReferenceRead
180+
];
181+
182+
183+
replaceNamedObjectContents[
184+
obj : feObjectPattern | Automatic : Automatic,
185+
spec:Next|Previous:Next,
186+
name_String,
187+
boxes_,
188+
ops:OptionsPattern[]
189+
] :=
190+
nameBoxApply[obj, spec, {ops},
191+
name,
192+
FrontEnd`BoxReferenceReplace,
193+
boxes
194+
];
195+
196+
197+
getNamedObjectOptions[
198+
obj : feObjectPattern | Automatic : Automatic,
199+
spec:Next|Previous:Next,
200+
name_String,
201+
All,
202+
ops:OptionsPattern[]
203+
] :=
204+
nameBoxApply[
205+
obj,
206+
spec,
207+
{
208+
ops,
209+
FE`BoxOffset -> {FE`BoxParent[1]}
210+
},
211+
name,
212+
FrontEnd`BoxReferenceGetOptions
213+
];
214+
getNamedObjectOptions[
215+
obj : feObjectPattern | Automatic : Automatic,
216+
spec:Next|Previous:Next,
217+
name_String,
218+
opt_?OptionQ,
219+
ops:OptionsPattern[]
220+
] :=
221+
nameBoxApply[obj, spec, {ops},
222+
name,
223+
FrontEnd`BoxReferenceGetOptions,
224+
opt
225+
]
226+
227+
228+
setNamedObjectOptions[
229+
obj : feObjectPattern | Automatic : Automatic,
230+
spec:Next|Previous:Next,
231+
name_String,
232+
options_,
233+
ops:OptionsPattern[]
234+
] :=
235+
nameBoxApply[obj, spec, {ops},
236+
name,
237+
FrontEnd`BoxReferenceSetOptions,
238+
options
239+
];
240+
241+
242+
(* UpValues interface on this *)
243+
FENamed /:
244+
BoxObject[
245+
FENamed[_, obj : feObjectPattern | Automatic : Automatic,
246+
name_String, ___],
247+
spec:Next|Previous:Next,
248+
ops:OptionsPattern[]
249+
] :=
250+
getNamedObject[obj, spec, name, ops];
251+
FENamed /:
252+
NotebookLocate[
253+
FENamed[_, obj : feObjectPattern | Automatic : Automatic,
254+
name_String, ___],
255+
spec:Next|Previous:Next,
256+
ops:OptionsPattern[]
257+
] :=
258+
selectNamedObject[obj, spec, name, ops];
259+
FENamed /:
260+
NotebookRead[
261+
FENamed[_, obj : feObjectPattern | Automatic : Automatic,
262+
name_String, ___],
263+
spec:Next|Previous:Next,
264+
ops:OptionsPattern[]
265+
] :=
266+
readNamedObjectContents[obj, spec, name, ops];
267+
FENamed /:
268+
NotebookWrite[
269+
FENamed[_,
270+
obj : feObjectPattern | Automatic : Automatic,
271+
name_String,
272+
___
273+
],
274+
spec:Next|Previous:Next,
275+
cnts_,
276+
ops:OptionsPattern[]
277+
] :=
278+
replaceNamedObjectContents[obj, spec, name, cnts, ops];
279+
FENamed /:
280+
HoldPattern[
281+
Options[
282+
FENamed[_,
283+
obj : feObjectPattern | Automatic : Automatic,
284+
name_String, ___
285+
],
286+
spec:Next|Previous:Next,
287+
opt:_?OptionQ|All:All,
288+
ops:OptionsPattern[]
289+
]
290+
] :=
291+
getNamedObjectOptions[obj, spec, name, If[Length@opt==0, All, opt], ops];
292+
FENamed /:
293+
SetOptions[
294+
FENamed[_, obj : feObjectPattern | Automatic : Automatic,
295+
name_String, ___],
296+
spec:Next|Previous:Next,
297+
opt_,
298+
ops:OptionsPattern[]
299+
] :=
300+
setNamedObjectOptions[obj, spec, name, opt, ops];
301+
302+
303+
End[];
304+
EndPackage[];

InterfaceObjects.nb

+9-3
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ Cell[BoxData[{
19831983
RowBox[{"Protect", "[", "InterfaceMethod", "]"}],
19841984
";"}]}], "CodeInput",ExpressionUUID->"c6ea0940-07cc-444a-8bac-aaa041467fb4"]\
19851985

1986-
}, Closed]],
1986+
}, Open ]],
19871987

19881988
Cell[CellGroupData[{
19891989

@@ -2330,7 +2330,7 @@ Cell[BoxData[
23302330
"\t\t\t\t\t\t", "]"}]}], ";"}]}], "\n", "\t\t\t\t", "]"}],
23312331
";"}]}], "\n", "\t\t\t", "]"}], ";"}]}], "\n", "\t\t", "]"}]}],
23322332
";"}]], "CodeInput",ExpressionUUID->"04ea9471-cead-4b28-92d6-5c9e3121282e"]
2333-
}, Closed]],
2333+
}, Open ]],
23342334

23352335
Cell[CellGroupData[{
23362336

@@ -2738,7 +2738,7 @@ Cell[BoxData[
27382738
"CodeInput",ExpressionUUID->"019e7c0f-bfe6-48a9-be66-2687bd71af2a"]
27392739
}, Open ]]
27402740
}, Closed]]
2741-
}, Closed]],
2741+
}, Open ]],
27422742

27432743
Cell[CellGroupData[{
27442744

@@ -2830,6 +2830,12 @@ e57495d40106"]
28302830
},
28312831
WindowSize->{808, 755},
28322832
WindowMargins->{{Automatic, 152}, {Automatic, 0}},
2833+
TaggingRules->{
2834+
"UUIDButtons" -> {
2835+
"Active" -> {
2836+
"Button-89ffd2c3-ec41-4179-a9b1-8e28670bca2c" -> False,
2837+
"Button-ca46e5e0-4fd1-47e8-8cf6-72998922b757" -> False,
2838+
"Button-a6d68254-3684-4d32-83fc-e5ef6f443930" -> False}}},
28332839
FrontEndVersion->"11.3 for Mac OS X x86 (32-bit, 64-bit Kernel) (March 5, \
28342840
2018)",
28352841
StyleDefinitions->FrontEnd`FileName[{"BTools"}, "CodePackage.nb",

WikiDataEntities.wl

+47
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,53 @@ wikidataEntityClassDataset[
438438
]
439439

440440

441+
(* ::Subsubsection::Closed:: *)
442+
(*wikiPropsScraping*)
443+
444+
445+
(*baseURL="https://www.wikidata.org/wiki/Category:Wikidata:List_of_properties";
446+
links:=Import[baseURL, "Hyperlinks"];
447+
propertyLists:=
448+
Pick[
449+
#,
450+
StringMatchQ[
451+
#,
452+
"https://www.wikidata.org/wiki/Wikidata:List_of_properties/"~~end:Except["/"]../;end=!="Summary_table"
453+
]
454+
]&@links;
455+
scrapeProps[link_]:=
456+
Module[
457+
{
458+
xml
459+
},
460+
xml=Import[link, {"HTML", "XMLObject"}];
461+
Cases[
462+
xml,
463+
XMLElement[
464+
"tr",
465+
_,
466+
{
467+
___,
468+
XMLElement["td", _,
469+
{
470+
___,t_String, ___
471+
}],
472+
XMLElement["td", _,
473+
{___, XMLElement["a", _, {v_}], ___}
474+
],
475+
___
476+
}
477+
]\[RuleDelayed]t\[Rule]v,
478+
\[Infinity]
479+
]
480+
]
481+
pullListIDs[lists_]:=
482+
AssociationThread[
483+
URLParse[lists, "Path"][[All, -1]],
484+
scrapeProps/@lists
485+
]*)
486+
487+
441488
(* ::Subsubsection::Closed:: *)
442489
(*$wikiDataProperties*)
443490

0 commit comments

Comments
 (0)