Data tiddler index combination

Hi Helpers,

I found the function of data tiddlers and index selection and it can help me to implement a function in my wiki I am looking for.
The best way to describe my requirement is an address book.

Germany : Europe
Italy : Europe
France : Europe
China : Asia
Berlin : Germany
Hamburg : Germany
Rome : Italy
Milano : Italy
Paris : France
Nice : France
Name_1 : Berlin
Name_2 : Berlin
Name_3 : Milano
Name_4 : Nice
Name_5 : Hamburg"

The function I am looking for is best described in this 3 requests:

  1. Request = “Name_1” and the answer is not only “Berlin”, I also want to get as result “Germany” and/or “Europe”
  2. Request = “Gemany” and the answer is “Europe”, I also want to get the result “Berlin”+“Hamburg” and/or “Name_1”+“Name_2”+“Name_3”
  3. request = “Europe” and than to have the possibility to get all countries and/or cities and/or names

Is there a chance to develop a filter or similar or any other idea to get it?

I thought about the possibility to use placeholder “***” like this and to use only one data tiddler, but I was not able to solve it also. Maybe I have to change the order? I do not know.

Name_1 : Berlin : Germany : Europe
Name_2 : Berlin : Germany : Europe
Name_3 : Milano : Italy : Europe
Name_4 : Nice : France : Europe
Name_5 : Hamburg : Germany : Europe
*** : Berlin : Germany : Europe
*** : Hamburg : Germany : Europe
*** : Rome : Italy : Europe
*** : Milano : Italy : Europe
*** : Paris : France : Europe
*** : Nice : France : Europe
*** : *** : Germany : Europe
*** : *** : Italy : Europe
*** : *** : France : Europe
*** : *** : China : Asia

Hopefully I described my use case so far that someone here can help me to find a solution. Every solution is welcome.

Thank you in advance
Stefan

As you can guess, there are several routes to take. But straight away, if you want to use index data tiddlers then each row needs a unique string before the : so the *** is not possible. (And I’m not sure the user of several : in one row is a good idea but maybe it’s not a problem, I’m just not sure.)

That last table in your post (which, as noted, will not work in its current format) indicates that you want all data in a single tiddler. Is that so, or is it as fine to use three separate data tiddlers?

I think the important words here are: “address book”. But you data structure does not look like an address book. It seems to be a lookup table with a lot of duplicated data.

Eg: Europe is there 3 times, that’s not needed if it would look as follows: (alphabetically sorted)

World: Afrika, Antarctica, Asia, Australia, Europe, North Amerika, South Amerika (alphabetically sorted)
Europe: Austria, Germany, Switzerland, France, Italy, UK, Ireland, others – more see: Europe - Wikipedia
Germany: Berlin, Hamburg, Munich ...
France: Paris, Nice, ...
Italy: Milano, Rome, ...

As you can see: Every bit of information is there only once. So changing anything will only be needed once.

I would have every Element in 1 tiddler. eg: World data is 1 tiddler, Europe, Germany, France … and so on. They are all separated and easy to extend.

For the tiddler Germany I would add eg:

cities: Berlin, Hamburg, München …
language-code: de-DE
phone-country-code: +41
…

Not all the info will be needed upfront, but it’s good to have the possibility later on.

The Contact would be a tiddler using fields instead of data-tiddlers. eg:

Name-1 tagged: Contact … The text field is there for additional notes about the contact.

Fields:

first-name:
sure-name:
company:
phone-1: 
phone-2:
email:
address-1:
address-2:
country: Germany 
city: Berlin 

country: … This field can have a custom template that shows all countries listed in Europe
city: … This field can have a custom template, that shows a dropdown with cities listed in Germany

and so on. So the initial elements from step 1 should only contain elements that you need, to keep the dropdowns shorter. (But the lists can easily be extended later on)

I hope that makes sense.

By the way, are the “names”, “countries” etc not better as individual tiddlers? I understand this is not your real use case, but still. TW is pretty much designed for your type of requests applied to tiddlers, but not so much for datatiddler content.

If they were tiddlers, then you can maybe use Bimlas Kin filter to explore relations. (I’ve never used it so maybe I’m off.)

I think this would be rather difficult to achieve and uncomfortable to use.

  • #1 looks for the ancestry of the input.
  • #2 looks for the parent of input. But you “also want to get” the children and/or the grandchildren.
  • #3 looks for the children “and/or” the grandchildren “and/or” the great-grandchildren (perhaps all descendants?)

I don’t know how we’d write a function that handles all those different types of functionality.

It’s easy enough to imagine extending what @pmario suggested and using a JSON tiddler with data something like this:

title: World

{
  "Africa": {}, 
  "Antarctica": {}, 
  "Asia": {"China": {}},
  "Australia": {}, 
  "North America": {}, 
  "South America": {},
  "Europe": {
    "Austria": {}, 
    "Germany": {
      "Berlin": {"Name_1": {}, "Name_2": {}}, 
      "Hamburg": {"Name_5": {}}, 
      "Munich": {}
    }, 
    "Switzerland": {},
    "France": {"Paris": {}, "Nice": {"Name_4": {}}}, 
    "Italy": {"Milano": {"Name_3": {}}, "Rome": {}}, 
    "UK": {}, 
    "Ireland": {}
  }
}

and then having a tool to take a location name, say, “Germany”, and return a structure like

{
  "Europe": {
    "Germany": {
      "Berlin": {"Name_1": {}, "Name_2": {}}, 
      "Hamburg": {"Name_5": {}}, 
      "Munich": {}
    }, 
  }
}

or flattening that into something like:

[
  "Europe|Germany|Berlin|Name_1",
  "Europe|Germany|Berlin|Name_2",
  "Europe|Germany|Hamburg|Name_5",
  "Europe|Germany|Munich"
]

But that doesn’t match what you asked for. I know of no good way to get what you asked for, though.

I agree with everyone who suggested that this should simply be a collection of distinct tiddlers for consistency and simplicity when using TW.

Every now and then, I’m dialed into a meeting where I have to hear the material but participate little and don’t really need to pay attention to the visuals. During those, I sometimes doodle, sometimes poke around code, and sometimes try to come up with a good answer to a question in these forums.

I just finished such a meeting, and am leaving the code in a reasonable place.

You can download this and drag it to a wiki (empty or https://tiddlywiki.com/ ,or whatever):

ttw9986.json (4.6 KB)

Then you can poke around starting with World, to see the hierarchy of Continent → Country → City → Name. Notice that all the locations and names are plain data tiddler, with just titles and tags. (In a real app, presumably they’d have more.) But the ViewTemplates demonstrate their place in the hierarchy.

Thus, for instance:

title: $:/_/my/templates/Country
tags: $:/tags/ViewTemplate

<% if [<currentTiddler>tag[Country]] %><$let country={{{ [<currentTiddler>] }}}>

; Continent
: {{{ [<currentTiddler>get[continent]] }}}
<% if [tag[City]tag<country>count[]!match[0]] %>
''Cities'' <<list-links filter:"[tag[City]tag<country>]">>
<% endif %>
<% if [tag[Name]] :filter[tags[]tag<country>] +[count[]!match[0]] %>
''Names'' <<list-links filter:"[tag[Name]] :filter[tags[]tag<country>]">>
<% endif %>
</$let><% endif %>

Will apply to “Germany” to give this:

I don’t know if this will be any help, but it was much more interesting than my meeting!

Thank you so far for your answers.

One more idea, is to use the output of a data tiddler request to use as index for another data tiddler.
Example:

title: Tiddler_city
type: application/x-tiddler-dictionary

Berlin : Germany
Paris : France
Rome : Italy
title: Tiddler_country
type: application/x-tiddler-dictionary

Germany : Europe
France : Europe
Italy : Europe
China : Asia
Canada : North America
title: Tiddler_name
type: application/x-tiddler-dictionary

Meyer : Germany
Schuster : Germany
Dubois : France
Rossi : Italy
Wang : China
Carpenter : Canada

How to use the result “Germany” from

<$transclude tiddler=“Tiddler_name” index=“Schuster” />

for a request

<$transclude tiddler=“Tiddler_country” index=result from above />

???

Than I can have as result:
Schuster - Germany - Europe

This will be much more than nothing and in the meantime I can look how to realize requests like “select
from tiddler_coutry if result is Europe”.

Is there someone woking to add basic sql functionality in TiddlyWiki?

Thank you again for your help.

Stefan

Instead of using $transclude to display the value of an index, you can use $list filters and “filtered transclusion” syntax (tripled curly braces) to retrieve the values into variables, and then display those variables.

For example, to show “name - country - continent” results for all names, you can do something like this:

<$list filter="[[Tiddler_name]indexes[]]" variable="name">
   <$let country={{{ [[Tiddler_name]getindex<name>] }}}
       continent={{{ [[Tiddler_country]getindex<country>] }}}>
      <<name>> - <<country>> - <<continent>><br/>
   </$let>
</$list>

enjoy,
-e

2 Likes

@EricShulman approach is an elegant way of nesting, one query with in another to follow the chain of data. You can use nested lists for this but Eric’s solution replaces the inner nest(s) with setting nested variables with let and evaluating multiple values (2) with filtered transclusions.