Filter links in Table

What I’m trying to do

I’m trying to filter out links within metadata.

I have a set of questions that may or may not be in the same file. I have different answers to those questions from different people. I’m trying to pull out the questions and answers for a particular person.

#questions
question::Question # 1?
answer::Answer 1.1 [[Person 1]]
answer::Answer 1.2. [[Person 2]]

question::Question # 2?
answer::Answer 2.1. [[Person 1]]
answer::Answer 2.2. [[Person 2]]

Desired Results:
| Question | Answer |
|Question # 1? | Answer 1.1. [Person 1] |
|Question # 2? | Answer 2.1. [Person 1] |

Things I have tried

The following examples show No Results:
Ex. 1
table question, answer
from #questions
where contains(answer, [[Person 1]])
Ex. 2
table question, answer, file.outlinks
from #questions
where contains(file.outlinks, “[[Person 1]]”)
Ex. 3
table question, answer, file.outlinks
from #questions
where contains(file.outlinks, “Person 1”)
Ex. 4
table question, answer
from #questions
where contains(string(file.outlinks), “[[Person 1]]”)
Ex. 5
table question, answer
from #questions
where answer = “[[Person 1]]”
Ex. 6
table question, answer
from #questions
where answer = [[Person 1]]
Ex. 7
table question, answer
from #questions
where file.outlinks = [[Person 1]]
Ex. 8
table question, answer
from #questions
where string(file.outlinks) = “[[Person 1]]”

The following examples show both people’s results.
Ex. 1
table question, answer
from #questions
where contains(answer, “[[Person 1]]”)
Ex. 2
table question, answer
from #questions
where contains(file.outlinks, [[Person 1]])
Ex. 3
table question, answer
from #questions
where contains(string(file.outlinks), “Person 1”)

All this means that you have a lot to learn in dataview. :slight_smile:
We can explain the query syntax or point to the best option in query side… but if the basic issue is related with the metadata structure, there’s nothing to do.

This is a recurrent misunderstanding. Why you think you’re writing a pseudo-groups of metadata?
If in one file you have this:

#questions

question::Question # 1?
answer::Answer 1.1. [[Person 1]]
answer::Answer 1.2. [[Person 2]]

question::Question # 2?
answer::Answer 2.1. [[Person 1]]
answer::Answer 2.2. [[Person 2]]

Your metadata structure for these fields is:

question:
  - Question # 1?
  - Question # 2?
answer:
  - Answer 1.1. [[Person 1]]
  - Answer 1.2. [[Person 2]]
  - Answer 2.1. [[Person 1]]
  - Answer 2.2. [[Person 2]]

As you can see, there’s no direct relation between values in question and in answer, i.e., there’s no groups of questions/answers in same file.

So, with your data structure you can’t make a reliable query.

1 Like

If you want to see the metadata structure in a specific file, place this inline query in that file (you need to enable js queries in settings > dataview):

`$=dv.span(dv.current())`

Topic

Summary
  • How to filter the data by the partial filename of a link or a list of links?
    • DQL10: Using nested list items=> A root list item starts with question:: and each of its children starts with answer::.

the note structure: case_FLST_LD

Summary

case_FLST_LD-DDD: use file.lists where the root L contains children and L.children contains three different DVIFs
FLST: Use file.lists
L : a root element of file.lists
D: DVIF
-DDD: L.children contains three different DVIFs (for example)

Take the following file as an example.
-DDD: L.children.answer, L.children.outlinks, L.children.tags

---
Date: 1991-04-01
---
#questions

- question::Question # 1?
    - answer::Answer 1.1. [[another Person]], [[some Person]] #Test/d01 


Test

Summary
  • dataview: v0.5.55

Input

Summary

dictionary files: for the DQL10

  • Location: “100_Project/02_dataview/Q18_QAA/Q18_test_data”

folder: 03

  • filename : dic_19910301
---
Date: 1991-03-01
---
#questions

- question::Question # 1?
    - answer::Answer 1.1. [[some Person]]
    - answer::Answer 1.2. [[another Person]]

- question::Question # 2?
    - answer::Answer 2.1. [[Person J]]
    - answer::Answer 2.2. [[Person K]]



folder: 04_a_root_list_item_and_its_clild

  • filename : dic_19910401
---
Date: 1991-04-01
---
#questions

- question::Question # 1?
    - answer::Answer 1.1. [[another Person]], [[some Person]] #Test/d01 


folder: 05_a_root_list_item_and_its_children

  • filename : dic_19910501
---
Date: 1991-05-01
---
#questions

- question::Question # 1?
    - answer::Answer 1.1. [[Person J]], [[some Person]]
    - answer::Answer 1.2. [[Person K]], [[another Person]]



folder: 06_children_null

  • filename : dic_19910601
---
Date: 1991-06-01
---
#questions

- question::Question # 1?
    - answer::
    - answer::



folder: 07_children_undefined

  • filename : dic_19910701
---
Date: 1991-07-01
---
#questions

- question::Question # 1?



folder: 08_undefined

  • filename : dic_19910801
---
Date: 1991-08-01
---
#questions




folder: 09_excluding_answer_without_links

  • filename : dic_19910901
---
Date: 1991-09-01
---
#questions

- question::Question # 1?
    - answer::Answer 1.1. "another Person"
    - answer::Answer 1.2. "some Person"



folder: 10_excluding_task_items

  • filename : dic_19911001
---
Date: 1991-10-01
---
#questions

- [ ] question::Question # 1?
    - [ ] answer::Answer 1.1. [[another Person]], [[some Person]]  #Test/d01 



DQL10_filter_by_partial_filename_of_a_link_or_a_list_of_links: case_FLST_LD-DDD

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10_filter_by
_partial_filename
_of_a_link
_or_a_list_of_links
LC.outlinks:
a link or a list of links
no 0.To require the note structure like case_FLST_LD-DDD

1.To filter the data by the partial filename of a link or a list of links
1.The Regular Expression declared as a variable like s_filename_of_link in the DQL10 is based on the DQL10 in the following topic.
- Solutions: by Justdoitcc

2.The Regular Expression declared as a variable like answer_without_outlinks in the DQL10 is based on the DQL10 in the following topic.
- Solutions: by Justdoitcc

Notes

Summary

Q1: How to modify the following code without filtering the data by answer_without_outlinks?

Summary_Q1
Original Example: Q1 (To be modified)
  • To filter the data by answer_without_outlinks
```dataview
FLATTEN regexreplace(LC.answer, "(\s+\[\[.+\]\].*$)", "") AS answer_without_outlinks
WHERE contains(answer_without_outlinks , "1.1.") OR contains(answer_without_outlinks , "1.2.")
```

A1_11:

Another Example: A1_11
  • Not to filter the data by answer_without_outlinks: remove the code as mentioned above.
```dataview

```

Q2: How to filter the data by the partial filename of a link(or a list of links) without using the FLATTEN operator?

  • To filter the data by partial filename of a link(or a list of links)
Summary_Q2
Original Example: Q2 (To be explained)
```dataview
FLATTEN map(LC.outlinks, (e) => regexreplace(meta(e).path, "^(.*/)(.+)(\.md)$", "$2")) AS s_filename_of_link
WHERE contains(s_filename_of_link , "another")
```

A2: (The same codes)

Another Example: A2_21
```dataview
WHERE filter(LC.outlinks, (e) => contains(regexreplace(meta(e).path, "^(.*/)(.+)(\.md)$", "$2") , "another"))
```

Another Example: A2_22
```dataview
WHERE any(LC.outlinks, (e) => contains(regexreplace(meta(e).path, "^(.*/)(.+)(\.md)$", "$2") , "another"))
```

Another Example: A2_23
```dataview
WHERE !none(LC.outlinks, (e) => contains(regexreplace(meta(e).path, "^(.*/)(.+)(\.md)$", "$2") , "another"))
```

Q3: How to filter the data by link(or string) of a link(or a list of links)?

  • To filter the data by link(or string) of a link(or a list of links)
Summary_Q3

A3: (The same codes)

Another Example: A3_31
```dataview
WHERE contains(LC.outlinks, [[another Person]])
```

Another Example: A3_32
```dataview
WHERE contains(LC.text, "[[another Person]]")
```

Another Example: A3_33
```dataview
WHERE contains(LC.answer, "[[another Person]]")
```

DQL Comments

Summary
# Code Data type In English Remark
1 TABLE WITHOUT ID 1.1 To display the result as a table
1.2 Not to display the default ID columns, File or Group
2 file.link AS “File”, …, s_filename_of_link AS “s_filename_of_link” 2.1 To display the content of a field variable file.link,…
2.2 To display the field label as “File”,…
3
4 FROM “100_Project/02_dataview/Q18_QAA/Q18_test_data” AND #questions FROM the folder and the tags
5
6 FLATTEN file.lists AS L a list=>a non-list 6.1 To break up a list like file.lists in a file into each individual element in a file
6.2 let L = each element of file.lists of each page;
7 WHERE !L.task To gather list items To exclude task items in the note dic_19911001
8 WHERE !L.parent AND L.question != null AND L.children 8.1 To gather root items
8.2 L.question does not strictly equal null
8.3 L.children is not an empty array
9
10 FLATTEN L.children AS LC a list=>a non-list 10.1 To break up a list like L.children in a file into each individual element in a file
10.2 let LC = L.children;
11 WHERE LC.answer != null AND LC.outlinks 11.1 LC.answer does not strictly equal null
11.2 LC.outlinks is not an empty array
12
13 FLATTEN map(LC.outlinks, (e) => regexreplace(meta(e).path, “^(.*/)(.+)(.md)$”, “$2”)) AS s_filename_of_link a list=>a non-list 13.1 To break up a list like LC.outlinks in a file into each individual element in a file
13.2 let s_filename_of_link = regexreplace...;
13.2 To get the filename from s_filename_of_link that is a copy of an element of LC.outlinks
14 WHERE contains(s_filename_of_link , “another”) s_filename_of_link contains “another” To filter the data by partial filename of a link(or a list of links)
15
16 FLATTEN regexreplace(LC.answer, “(\s+[[.+]].*$)”, “”) AS answer_without_outlinks let answer_without_outlinks = regexreplace...; To remove the LC.outlinks string from answer_without_outlinks that is a copy of LC.answer
17 WHERE contains(answer_without_outlinks , “1.1.”) OR contains(answer_without_outlinks , “1.2.”) 17.1 answer_without_outlinks contains “1.1.”
17.2 answer_without_outlinks contains “1.2.”
To filter the data by answer_without_outlinks
18
19 SORT file.link ASC To sort by file.link in ascending order

Code DQL10_filter_by_partial_filename_of_a_link_or_a_list_of_links: case_FLST_LD-DDD

Summary_code
title: DQL10_filter_by_partial_filename_of_a_link_or_a_list_of_links=>0.To require the note structure like case_FLST_LD-DDD
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      file.link AS "File",
      L.question AS "Question",
      LC.answer AS "Answer",
      answer_without_outlinks AS "Answer_without_outlinks",
      LC.outlinks AS "LC_outlinks",
      s_filename_of_link AS "s_filename_of_link"

FROM "100_Project/02_dataview/Q18_QAA/Q18_test_data" AND #questions

FLATTEN file.lists AS L
WHERE !L.task
WHERE !L.parent AND L.question != null AND L.children

FLATTEN L.children AS LC
WHERE LC.answer != null AND LC.outlinks

FLATTEN map(LC.outlinks, (e) => regexreplace(meta(e).path, "^(.*/)(.+)(\.md)$", "$2")) AS s_filename_of_link
WHERE contains(s_filename_of_link , "another")

FLATTEN regexreplace(LC.answer, "(\s+\[\[.+\]\].*$)", "") AS answer_without_outlinks
WHERE contains(answer_without_outlinks , "1.1.") OR contains(answer_without_outlinks , "1.2.")

SORT file.link ASC

```

Screenshots(DQL10)


Reference

Summary

Q88_Links

Q92_FileLists > DQL10


3 Likes

Thanks for the info. This is just what I was looking for.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.