Semantic Mediawiki: trying to query subobjects - mediawiki

I've page with a long list of subojects. The properties are correctly visibile. I've successfully queried that list from the same page and not I'm trying from another page:
I've magaed to point to the page, to filter for the tag, but it doesn't work as expected: it returns many tags (while it should return only one), it returns no title and 1 url.
{{#ask: [[-Has subobject::Tutti gli articoli di Marco Crepaldi]] [[Tags::femminicidi]]
|?tags
|?title
|?url
| mainlabel=-
}}

Related

MediaWiki Semantic Template: Property "Title" (as page type) with input value

A few months ago I asked a very similar question but the cause of the problem this time is different.
The error message is:
Property "Title" (as page type) with input value "Lo psicologo di base rischia di essere inutile se non ci sono abbastanza fondi stanziati
italianTitle = {{{italianTitle}}}" contains invalid characters or is incomplete and therefore can cause unexpected results during a query or annotation process.
Here I'm using an {{#if inside a template.
The property italianTitle is optional
<includeonly>[{{{url}}} {{#if:{{{italianTitle|}}}|{{{italianTitle}}}|{{{title}}}}}] - {{{tags}}} {{#subobject:
|url = {{{url}}}
|title = {{{title}}}
{{#if:{{{italianTitle|}}}|
|italianTitle = {{{italianTitle}}}
}}
|tags={{{tags}}}|+sep=,}}</includeonly>
<noinclude>
{{man}}
== Esempi:==
{{SemanticLink|url=https://www.instagram.com/p/CY_t7QhIWTD/|title=Lo psicologo di base rischia di essere inutile se non ci sono abbastanza fondi stanziati|tags=psicologia,governo,politica,lavoro}}
{{SemanticLink|url=https://www.instagram.com/p/CY_t7QhIWTD/|title=english title|italianTitle=italian title|tags=psicologia,governo,politica,lavoro}}
This MediaWiki template is used to create a semantic link, which is a link to a webpage with additional information (in a Semantic Mediawiki subobject) such as a title and tags.
The template has the following parts:
The first part, [{{{url}}} {{#if:{{{italianTitle|}}}|{{{italianTitle}}}|{{{title}}}}}], creates the link to the webpage specified by the "url" parameter. It also displays the title of the webpage, which can be specified by either the "title" or "italianTitle" parameter.
The #if function checks if the "italianTitle" parameter is passed, if it is, it will be used as the title, otherwise, the title parameter will be used.
The second part, {{{tags}}}, displays the tags associated with the webpage, which can be specified by the "tags" parameter.
The third part, {{#subobject:|url = {{{url}}}|title = {{{title}}}|italianTitle = {{{italianTitle}}}|tags={{{tags}}}|+sep=,}}, creates a subobject which is a container for additional information related to the link. Here it contains the url, title, italianTitle and tags parameters. The +sep=, is used to separate the tags with a comma when they are displayed.
The triple curly brackets, {{{ }}} , are used to define template parameters.
When the template is used on a page, the text inside the curly brackets is replaced by the value passed to the corresponding parameter.
For example, the {{{url}}} will be replaced by the value passed to the "url" parameter when the template is used, {{{title}}} will be replaced by the value passed to the "title" parameter and so on.

How to access metadata when using "where" filter

I've got a structured set of pages in a collection, and the structure looks something like this:
chapter1
section1
section2
section3
chapter2
section1
section2
section3
chapter3
section1
section2
section3
Each is a separate page that renders its own permalink.
Say I'd like to make a link to chapter3/section1, how would I do this? I'd like to use the Liquid where filter, but this seems to give me the page contents, not the metadata.
{% assign section_post = site.chapters | where:"url","chapter3/section1" %}
{{ section_post }}
This gets me the proper page, but not the right content. If I were to write this in my layout, I get nothing:
{{ section_post.title }}
What am I doing wrong? How can I get the metadata using a where filter? I've got a bunch of pages, so looping through them is super inefficient...
The problem is that a where expression returns all the objects in an array given a certain condition.
[#<Jekyll::Document _chapters/chapter3/section1 collection=chapters>]
In this case you are expecting that this list of objects just return a single item, so we can select that item with the first liquid tag (returns the first element of an array).
{% assign ch3s1 = site.chapters |
where:"id","/chapters/chapter3/section1" | first%}
title: {{ch3s1.title}}
<br>
url: {{ch3s1.url}}
would output the desired section:
title: Chapter 3 section 1
url: /chapters/chapter3/section1

IE automation VBA Excel find element by title

I am trying to get some information from a webpage using an excel macro, VBA.
I have the InternetExplorer.document object, but don't find a way to locate the exact info that I need.
The HTML part of what I am looking for looks like this:
<a title="BE xxx.xxx.xxx - straat 70 - 3630 - Maasmechelen" class="leftalign floatleft" href="Page_companydetail.asp?vat=xxxxxxxxx" target="_blank">
Oprichter van een onderneming natuurlijk persoon BE xxx.xxx.xxx
The information I want is the title here.
I tried a lot of things, but can't manage to single this element out and get the title.
So
1. Is there a way to get elements by title (Title starts with BE), or by class sinds this information is the only one on the page that has class "leftalign floatleft"
Yes ... knowing that the title is just another attribute of the <a> tag, you can cycle through all elements of concern using e.g.
HtmlDocument.GetElementsByTagName(String) method
and use the
HtmlElement.GetAttribute(String) method
to see if a title attribute exists and what's the value of it
see Reading Web Pages using Excel VBA for some more information
Something like this should work, I'm assuming you already have a pointer to the IE or Document Object.
Public Sub getTitleElement()
Dim myElement As Object
'Assuming you already have IE object/Document
Set myElement = IE.Document.getElementsByClassName("leftalign floatleft")(0)
Debug.Print myElement.Title
End Sub

Mediawiki API: How do I list all pages of a category and for each page show all of it's categories?

I am using the following wikimedia API to list all pages with a certain category: https://www.mediawiki.org/wiki/API:Categorymembers
E.g. https://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Physics
This gives me a list of pages with title and id, but I would also like to see all categories for each page. However it seems that there is no cmprop for that.
cmprop: Which properties to get. (Default: ids|title)
ids: Page ID
title: Page title
sortkey: The sortkey used for sorting in the category (hexadecimal string)
sortkeyprefix: The sortkey prefix used for sorting in the category (human-readable part of the sortkey) 1.17+
type: Type that the page has been categorised as (page, subcat or file) 1.17+
timestamp: Time and date the article was added to the category
I have considered to query each page and use prop=categories to get the categories for each page, but that would mean a very large number of queries. Is there any better way of doing this?
You can use categorymembers as a generator. If you do that, you can then apply prop=categories:
https://en.wikipedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=categories&cllimit=max&gcmlimit=max

Semantic mediawiki #ask query: Displaying nested properties on the same query

I would like to display in the same query properties of a page which is related to the pages im querying for.
Let's say I would like to query all the pages in the City category, which are located in Germany, and I want to display the title of the page, but also I want to display the surface data of Germany, for example.
Something like this: {{#ask: [[Category:City]] [[location::Germany]] |?mainlabel |?Location.surface }}
I know this wont work, but you can see what I want to achieve.
I'm not sure if there's a way to nest queries directly inside other queries. The normal method of doing it is using a template. So you might define a template (or subpage of the template if this going into a template) called {{tablerow}} that consists of:
<includeonly>
|- valign="top"
| [[{{{1|}}}]]
| {{#show: {{{1|}}} | ?surface }}</includeonly>
The <includeonly> tags are important for reasons I don't really understand, it produces errors sometimes if you leave them out. Then you just run an #ask query with format = template. (You can build the header into the query, but I find it simpler to just put it outside.)
{| class="wikitable smwtable sortable"
|- valign="bottom"
! [[City]]
! [[Surface]]
{{#ask: [[Category:City]] [[location::Germany]]
| format = template
| template = tablerow
| link = none
}}
|}
That will punch each result returned by the query through the template as {{{1}}} and generate a row based on it. If you have other data to return from the main query, additional properties that you ask for will come out as consecutive unnamed parameters (so if you include | ?population, that will go into the template as {{{2}}} and will need to be added to the row structure or it will be dropped).