taxonomy terms – How do I set up an article view that validates both article and category?

I’m working with Drupal 7, and trying to get a view set up that will display blog categories and articles based on their category.

The category is a Taxonomy – Blog Categories – let’s assume it’s:

  • rock-and-roll
  • pop
  • jazz
  • other

I’m hoping for the following path behavior:

  1. /blog/ should list all articles.
  2. /blog/rock-and-roll/ should list articles that have the rock-and-roll taxonomy set.
  3. /blog/non-existant-term/ should show page not found
  4. /blog/rock-and-roll/real-article-title should show the relevant article
  5. /blog/rock-and-roll/fake-article-title should show page not found

I’ve tried a ton of different combinations of relationships and contextual filters, but I just can’t get it to work. The closest I can get is where all of the ‘proper’ urls work… I get category lists, or I get article displays… but I also still get a page when I go to a path with either an invalid taxonomy term or an invalid article name.

It seems like it should be something with the Contextual Filter validation stuff… but anything I’ve tried with like validation based on a taxonomy or whatever just stops anything from working. I no longer get listings or articles properly.

I’m not sure what other information to include – I’m trying to avoid adding any modules (because I’ve basically been told not to) and I’m trying to avoid making it multiple views.

——– EDIT ——–

I’ve tried some of the stuff suggested by prkos but I’m not having any more success. I’ve attached some screenshots of my configs… with a little bit of censored stuff. It probably doesn’t matter, but I’m expected to be circumspect.
The original URL/Taxonomy I used isn’t actually the final stuff, it was just example… so there might be some mismatch there.

Main view config
Relationship config
Contectual Filter config

So, with these changes in place… now if I go to url/news2/ I get a Page not found. url/news2/all seems to work, but then url/news2/validterm doesn’t work. validterm doesn’t get any results in the view preview thing either… where it did before.

list of of terms to be displayed

I have a node (type = List) with 2 fields, Term Name and Body.
Body is a long text type field and Term Name is a entity reference field, which is a drop down with a list of Term in Vocabulary Vocab.

Lets say Terms are Term1 and Term2 in Vocab.
My Requirement is

  1. user creates new content Node 1. Term Name field should display all the Terms in Vocabulary Vocab. user selects the Term1 and saves the content.

  2. user creates new node Node 2, Term Name field dropdown should display only Term1. as values.

So in short, if there is any node created by a user, Term Name field should contain on term selected in already created node. if there is no node created by user all term names should be displayed.

Any idea how i can achieve this I am using Drupal 7.x

list manipulation – How to delate certain terms in a polynomial with varibales in subscript?

I have a polynomial in the following style,

polynomialdata= Subscript[xy, 1, 1][0]*Subscript[xy, 1, 2][0] + Subscript[xy, 1, 1][0]*Subscript[xy, 2, 1][0] +  Subscript[xy, 1, 2][0]*Subscript[xy, 2, 2][0] +  Subscript[xy, 2, 1][0]*Subscript[xy, 2, 2][0] + Subscript[xy, 1, 1][0]*Subscript[xy, 1, 2][0]*Subscript[xy, 2, 1][0]*Subscript[xy, 2, 2][0] + Subscript[xy, 2, 1][0]*Subscript[xy, 3, 1][0] + Subscript[xy, 1, 1][0]*Subscript[xy, 1, 2][0]*Subscript[xy, 2, 1][0]*Subscript[xy, 3, 1][0]

I wonder how to remove certain terms in the polynomialdata such as Subscript[xy, 2, 1][0] Subscript[xy, 3, 1][0] or keeping terms such as Subscript[xy, 1, 1][0]*Subscript[xy, 1, 2][0]*Subscript[xy, 2, 1][0]*Subscript[xy, 3, 1][0].

Probably one stupid way is to do the following

Keep[expr_] := 
 expr /. {Subscript[xy, 1, 1][0]*Subscript[xy, 1, 2][0]-> 0, Subscript[xy, 1, 1][0]*Subscript[xy, 2, 1][0]-> 0, Subscript[xy, 1, 2][0]*Subscript[xy, 2, 2][0]-> 0, Subscript[xy, 2, 1][0]*Subscript[xy, 2, 2][0] -> 0, Subscript[xy, 2, 1][0]*Subscript[xy, 3, 1][0]-> 0}

Keep[data]

the result gives 0; which is not I expected.

I want the outcome to be Subscript[xy, 1, 1][0]*Subscript[xy, 1, 2][0]*Subscript[xy, 2, 1][0]*Subscript[xy, 2, 2][0] + Subscript[xy, 1, 1][0]*Subscript[xy, 1, 2][0]*Subscript[xy, 2, 1][0]*Subscript[xy, 3, 1][0]. Maybe I could use DeleteCases function.

However, if the data has many terms, it will be very inefficient to do the above removing. Is there any way to solve it? Thank you very much in advance!

optimization – In a language interpreted line by line – is optimizing similar lines of code within a module into functions better in terms of efficiency?

Python does not interpret line by line. The default Python implementation (CPython) compiles the entire module to bytecode and then runs it. However, the CPython implementation does not place an emphasis on optimizations. The interpreter will do exactly what you tell it to do, which means that small changes to your code can have a big performance effect. In particular, function or method calls are relatively “slow” in CPython.

But in absolute terms, it doesn’t matter for performance. You’re writing code for GUI automation. The interaction with the GUI will be far slower than calling a function or parsing some lines of code. This is a bit like being on a journey between two cities. You are proposing to take a shortcut that will save you a minute on this tour, when you’ll actually spend an hour waiting in an airport to board a flight.

So performance doesn’t really matter here. What does matter? Maintainability. Instead of copy and pasting the same code four times, it is usually better to clearly separate the things that stay the same from the things that differ between instances of this code. A function is the perfect tool to express that. Thus, while your alternative solution with a function might run 200 nanoseconds slower, it is the objectively better approach here.

In reality, writing maintainable code with good abstractions is good for performance. When your code is easy to understand, it is easier to understand how performance can be improved, and to implement those improvements. For example, if you find that there’s a faster alternative for the checkExists() method, you’ll now only have to update it in one place. Of course, most code is not performance-critical, so such optimizations are unlikely to have a noticeable effect.

computer science – Smallest grammar problem formulated in terms of minimizing a monoid homomorphism into $(Bbb{N}, +, leq)$. What is an algorithm for computing one?

Let the naturals $Bbb{N}$ include $0$.

Let $A = {a,b,c, dots}$ be a finite alphabet of symbols.

Definition 1. A grammar of a string $s in A^*$ is a monoid homomorphism $varphi : A^* to A^*$ such that the iterates $varphi^i(X), i geq 0$ stabilize to $s$ for some $X in A$.

Observation 1. The set of all grammars of strings in $A^*$ forms a monoid $M_A$ under pointwise multiplication.

Definition 2. The size function on $M_A$ is the monoid homomorphism $|cdot | : M_A twoheadrightarrow (Bbb{N}, +)$ given by $|varphi| = sum_{a in A} | varphi(a)|$, where $|varphi(a)|$ simply takes the symbol string length.

Remark 1. $(Bbb{N}, +)$ forms an ordered monoid, so we can speak of $leq$.

Definition 3. A smallest grammar of a string $s in A^*$ is a grammar of $s$, such that for all other grammars $psi$ of $s$, $|varphi| leq |psi|$.

Observation 2. Minimizing the size function above is essentially the same thing as the smallest grammar problem (SGP), where the standard size function is the sum over all variable symbols instead:

$$
| varphi | = sum_{X in in text{variables}(varphi)} |varphi(X)|
$$

. This is true since including the terminals simply adds a constant to the standard size function that you’re minimizing when solving the SGP.

Remark 2. If a grammar does not “make use of” a symbol $x$, then it simply gets mapped to the empty string $varepsilon$ which has length $0$ and thus no contribution to the final grammar size.


Question. using the above definitions, what is an algorithm (regardless of its efficiency) for computing a smallest grammar or alternatively the set of all smallest grammars, of a given input string $s$?


Define $text{supp}(varphi) = { a in A: varphi(a) neq varepsilon}$. Notice that if $varphi$ is a smallest grammar of $s$ and $psi$ is a smallest grammar of $t$, and $text{supp}(varphi) cap text{supp}(psi) = varnothing$, then $varphipsi$ is a smallest grammar of $st$. This is because there are no shared substrings, and so the smallest grammars can be computed independently.

Can we use this fact somehow in an algorithm?

In none of the literature on the smallest grammar problem do they present an algorithm for computing exactly the smallest grammar or set of smallest grammars. All literature on the topic focuses on approximating them.

I want to see an algorithm for computing them exactly. So how would one be written?

expression of $partial_z$ in terms of $x$ and $y$ with $z=a(x^2+y^2)$

Assume we have a function with the term $partial_z f(z)$, where $z=a(x^2+y^2)$, $ain mathbb{R}$. If I want to express the function in terms of $x$ and $y$, how would I express $partial_z$?

taxonomy terms – alter query view by adding fields in an andGroup within an orGroup

I have a multilanguage site with two languages: English and Dutch.
Not all nodes are created in both languages. Some nodes even have no language (‘und’, ‘zxx’).

I want the default Drupal provided taxonomy view output all nodes of a taxonomy-term in the current and no node-language, AND, if present, other nodes of this term from the other language.
The Drupal provided sql is:

SELECT "taxonomy_index"."sticky" AS "taxonomy_index_sticky", "taxonomy_index"."created" AS "taxonomy_index_created",
"node_field_data"."nid" AS "nid", "node_field_data"."langcode" AS "node_field_data_langcode"
FROM {node_field_data} "node_field_data"
LEFT JOIN {taxonomy_index} "taxonomy_index" ON node_field_data.nid = taxonomy_index.nid
WHERE ((taxonomy_index.tid = '14')) AND (("node_field_data"."langcode" IN ('nl', 'und', 'zxx'))
AND ("taxonomy_index"."status" = '1'))
ORDER BY "taxonomy_index_sticky" DESC, "taxonomy_index_created" DESC
LIMIT 11 OFFSET 0

I want, if applicable, extend the where clause so it becomes by example:

WHERE (((taxonomy_index.tid = '14')) AND ((("node_field_data"."langcode" IN ('en', 'und', 'zxx'))
AND ("taxonomy_index"."status" = '1')))
OR (("taxonomy_index"."tid" = '14') AND ("node_field_data"."nid" IN ('43'))
AND ("node_field_data"."langcode" NOT IN ('en', 'und', 'zxx'))))

I wrote a function example_views_query_alter(ViewExecutable $view, QueryPluginBase $query) in which I found out which extra nodes should be added in the extra OR clause. By adding this code:

      $group_id = $query->setWhereGroup('OR');
      $query->addWhere($group_id, 'taxonomy_index.tid', $tid);
      $query->addWhere($group_id, 'node_field_data.nid', $missing, 'IN');
      $query->addWhere($group_id, 'node_field_data.langcode', $langcodes2, 'NOT IN');

But in the extended where clause I get OR instead of AND statements:

WHERE ((taxonomy_index.tid = '14')) AND ((("node_field_data"."langcode" IN ('en', 'und', 'zxx'))
AND ("taxonomy_index"."status" = '1'))
OR (("taxonomy_index"."tid" = '14') OR ("node_field_data"."nid" IN ('43'))
OR ("node_field_data"."langcode" NOT IN ('en', 'und', 'zxx'))))

But it should be an AND group within an OR Group, maybe like:

$query->setWhereGroup('OR');
$query->setWhereGroup('AND');
$query->addWhere(...

Who can help me out to achive this?

8 – Conditional Show/Hide Child Terms on Edit Page

I have a content type with a term reference. The terms have child terms. On the admin editing side, I want to show only top level terms until selected, then show only the child terms for that parent.

This to prevent having a ginormously long field.

Parent 1
  Child 1
  Child 2
Parent 2
  Child 3
  Child 4
Parent 3
...

When a user edits a piece of content, I want to only show the parent terms initially. Then show/hide the child terms when the parent is checked.

Parent 1
Parent 2 (checked)
  Child 3
  Child 4
Parent 3
Parent 4
...

I’ve used conditional fields, state API, and select (other) modules. But this is showing and hiding children on the same field. So it’s a bit different.

Anyone have any advice for this scenario?

mysql – Is using strings as keys for reference to other tables bad in terms of memory usage?

Yes MySql and all other rdms will store the complete email as varchar and reserve space for the number of bytes.

Integer with up to 8 bytes for a big integer will on löy use these bytes, and are so faster when referencing.

In terms of speed you use INTEGER, and consider other like varchar(36) for uuids when the need arises, for example different servers have to save data in the same table.

whith emails a unique and so be indexed for referencing, you should take the extra mile and use Integer if you expect you will have big tables.