Skip to main content
Added url hyperlinks
Source Link
vindobona
  • 6.3k
  • 1
  • 15
  • 33

Edit 1: Added url hyperlinks

inventory={
  {"https://lex.uz/en/docs/3815506", {"plant protection", "land plot", "agricultural production"}},
  {"https://lex.uz/en/docs/6906672", {"environmental protection", "land plot"}}};

ds = Query[All, {"url" -> URL}]@
       Dataset[AssociationThread[{"url", "tags"} -> #] & /@ inventory]

lookup[words__] :=
 Query[
   Select[
    Or @@ 
      Map[word |-> StringContainsQ[StringRiffle[#tags, "|"], word], words] &]
   , {"url", "tags"}]@ds

words = {"prot", "agri"};
lookup[words] [All, "url"] // Normal

{"httpsURL["https://lex.uz/en/docs/3815506"3815506"], "https URL["https://lex.uz/en/docs/6906672"6906672"]}

words = {"envi"};
lookup[words] [All, "url"] // Normal

{"httpsURL["https://lex.uz/en/docs/6906672"6906672"]}

inventory={
  {"https://lex.uz/en/docs/3815506", {"plant protection", "land plot", "agricultural production"}},
  {"https://lex.uz/en/docs/6906672", {"environmental protection", "land plot"}}};

ds = Dataset[AssociationThread[{"url", "tags"} -> #] & /@ inventory]

lookup[words__] :=
 Query[
   Select[
    Or @@ 
      Map[word |-> StringContainsQ[StringRiffle[#tags, "|"], word], words] &]
   , {"url", "tags"}]@ds

words = {"prot", "agri"};
lookup[words] [All, "url"] // Normal

{"https://lex.uz/en/docs/3815506", "https://lex.uz/en/docs/6906672"}

words = {"envi"};
lookup[words] [All, "url"] // Normal

{"https://lex.uz/en/docs/6906672"}

Edit 1: Added url hyperlinks

inventory={
  {"https://lex.uz/en/docs/3815506", {"plant protection", "land plot", "agricultural production"}},
  {"https://lex.uz/en/docs/6906672", {"environmental protection", "land plot"}}};

ds = Query[All, {"url" -> URL}]@
       Dataset[AssociationThread[{"url", "tags"} -> #] & /@ inventory]

lookup[words__] :=
 Query[
   Select[
    Or @@ 
      Map[word |-> StringContainsQ[StringRiffle[#tags, "|"], word], words] &]
   , {"url", "tags"}]@ds

words = {"prot", "agri"};
lookup[words] [All, "url"] // Normal

{URL["https://lex.uz/en/docs/3815506"], URL["https://lex.uz/en/docs/6906672"]}

words = {"envi"};
lookup[words] [All, "url"] // Normal

{URL["https://lex.uz/en/docs/6906672"]}

Source Link
vindobona
  • 6.3k
  • 1
  • 15
  • 33

inventory={
  {"https://lex.uz/en/docs/3815506", {"plant protection", "land plot", "agricultural production"}},
  {"https://lex.uz/en/docs/6906672", {"environmental protection", "land plot"}}};

ds = Dataset[AssociationThread[{"url", "tags"} -> #] & /@ inventory]

lookup[words__] :=
 Query[
   Select[
    Or @@ 
      Map[word |-> StringContainsQ[StringRiffle[#tags, "|"], word], words] &]
   , {"url", "tags"}]@ds

words = {"prot", "agri"};
lookup[words] [All, "url"] // Normal

{"https://lex.uz/en/docs/3815506", "https://lex.uz/en/docs/6906672"}

words = {"envi"};
lookup[words] [All, "url"] // Normal

{"https://lex.uz/en/docs/6906672"}