PHP – Dynamically apply parsing rules to text, and save to dynamic fields

OK, so I have been at this problem for the last few days, and I must admit – I am stuck.

I am trying to make a web application, where users can upload documents or send inbound e-mails.

Each document or email will be added to a stream. So a stream holds all the docs/mails.

Now, what I want to allow my users are the following:

  1. Users should be able to add ┬┤fields┬┤ to a stream. A field is essentially just a dynamic variable, that users can set. So for example, if a user uploads a large text file, they can eg. create below fields: 1.1 Order number 1.2 Tracking reference

  2. Users can then add parsing rules to each field. A parsing rule can consist of multiple methods. For example: remove_empty_lines text_replace regex_text_replace Users can apply as many parsing rules to the text string as they want. Everytime a new parsing rule has been applied, the new and updated text string will be stored in parsing_rule_results

OK so above describes the workflow, that a user can setup for each document/email, and above is bound pr. stream.

Now, what I want to achieve is the following:

  1. For each new document/email that is added to my application, I need to check what fields is defined for the specific stream.
  2. For each field defined, I need to run the string through each parsing_rule, and
  3. ultimately, once the the string has been run through each parsing rule, the end result should be dynamically saved to that specific document/email. Something like:

id | field | document_id | email_id | data

1 | 3 | 5 | null | 5000251 2 | 4 | 5 | null | AJIWO4124124J 3 | 3 | 6 | null | 92841 4 | 4 | 6 | null | KKLJPEPQ9102 5 | 3 | 6 | null | E-Order2000 6 | 4 | null | 2 | OOCLTCU8291LK 

Which can be translated into:

Stream: 1

Document ID # 5:

  1. order_number= “5000251”

  2. tracking_number = “AJIWO4124124J”

Document ID # 6:

  1. order_number= “92841”

  2. tracking_number = “KKLJPEPQ9102”

Email ID # 2:

  1. order_number= “E-Order2000”

  2. tracking_number = “OOCLTCU8291LK”

Below is the beginning of my database design – but without “field results”.

My database setup

This is the code I have so far (models):


    // A stream can have many documents     public function documents()     {         return $  this->hasMany(Document::class);     }      //A stream can have many e-mails     public function emails()     {         return $  this->hasMany(Email::class);     }      //A stream can have many fields     public function fields()     {         return $  this->hasMany(Field::class);     }     //A stream have fields, which then have parsing rules.     public function parsingRules()     {         return $  this->hasManyThrough(ParsingRule::class, Field::class);     } 


    //A document belongs to a Stream.     public function stream()     {         return $  this->belongsTo(Stream::class);     }      // A document will have fields.     public function fields()     {         return $  this->hasMany(Field::class, 'stream_id', 'stream_id');     } 


    // An email belongs to a Stream.     public function stream()     {         return $  this->belongsTo(Stream::class);     }      //An email will have fields.     public function fields()     {         return $  this->hasMany(Field::class, 'stream_id', 'stream_id');     } 


   // A field belongs to a Stream     public function stream()     {         return $  this->belongsTo(Stream::class);     }      // A field can have many parsing rules.     public function parsingRules()     {         return $  this->hasMany(ParsingRule::class);     } 


    //A parsing rule belongs to a field.     public function field()     {         return $  this->belongsTo(Field::class);     } 

I believe the real problem I have lies in my understanding of relationships, and how I should dynamically apply above logic.

Let’s imagine I have a class, that will be called whenever a new document/email is being added:


    public function parse(Document $  document)     {              $  text = $  document->text;          $  stream = $  document->stream();          $  fields = $  document->fields();           //1. get all $  parsing_rules for each $  fields.           //2. parse $  text by using each $  parsing_rule           //3. save the end result of $  text by document/email specific and field.       } 

As you can see, I can fetch the stream details as well as the fields for the specific stream.

However – how can I:

  1. Make it so it allows both Email and Document, depending on what is being added? (Above only allows Document)
  2. Run through each field, and subsequently parse through each parsing_rule and save the end result, so it’s specific for each document/email

I hope above is somewhat clear. This post got a lot longer than first expected.

Rules for cutting / removing bow string during combat [duplicate]

This question already has an answer here:

  • How can I attack an enemy's weapon? 1 answer

If a Rogue gets into melee combat with another combatant wielding a bow, what actions are permitted to disable the bow?

Could the Rogue use sleight oft hand to unhinge the bow string?

Could he make a melee attack to cut the string or destroy the bow or does he have to disarm the opponent and make him drop his weapon before he may destroy it?

I couldn’t find any rules on how to handle such a situation as a DM.

Strictly Proper Scoring Rules and f-divergences

Let $ S$ be a scoring rule for probability functions. Define

$ EXP_{S}(Q|P) = \sum \limits_{w} P(w)S(Q, w)$ .

Say that $ S$ is striclty proper if and only if $ S$ minimises $ EXP_{S}(Q|P)$ as a function of $ Q$ . Define

$ D_{S}(P, Q) = EXP_{S}(Q|P) – EXP_{S}(P|P)$ .

If $ S$ is the logarithmic scoring rule defined by $ S(P, w) = -ln(P(w))$ , then $ D_{S}(P, Q)$ is just the Kullback-Leibler divergence between $ P$ and $ Q$ , or equivalently, the inverse Kullback-Leibler divergence between $ Q$ and $ P$ . Note that the inverse Kullback-Leibler divergence is an $ f$ -divergence.

My question is this: is there any other strictly proper scoring rule $ S$ such that $ D_{S}(P, Q)$ is equal to $ F(Q, P)$ for some $ f$ -divergence $ F$ ?

I think that $ D_{S}(P, Q)$ is always a Bregman divergence, and Amari proved that the only $ f$ -divergence that is also a Bregman divergence is the Kullback-Leibler divergence (on the space of probability functions). Is this enough to imply that there are no other strictly proper scoring rules with this property?

URL Argument via rules

I have a custom link that adds automatically an article into my webshop. I also added data that is adding the e-mail address from the client.

I have following setup in my rules:

Event: Quick add to cart link was accessed

Conditions: Check if URL argument exists (email)


  • Adding a product to shopping cart (id 011)
  • Provide URL argument value (email)
  • Set a data value [site:current-cart-order:mail] – value: [argument-from-url-name]
  • Page redirect:

-> So, when I go to it automatically adds product ID 011 into my shopping cart and goes directly to my checkoutpage and e-mail address “” is also filled in.

Now I want to go further. I want to have the possibility to have a custom URL like:

So not only the field e-mail has to be filled in, but also my field ‘name’ and my custom field that I’ve added to ‘shipping information’.

I’m unable to have this working, I’ve really tried everything by Entity has field,… but without no succes.

Does anybody knows which rules I have to add extra to have this working?

What are Rules for concealing thieves tools (or items in general)?

I’m playing a rogue assassin in my current campaign, and I’m about to embark on an infiltration mission where I’ll be wearing formal attire. I told the DM I would want to conceal a few lockpicks on my person, but was told (because he was not sure how to rule it) that I would need specifically made attire to accomplish this.

This seemed a little odd to me, and I swear I saw a ruling on this topic somewhere, but haven’t been able to find it. Is there an established rule/official ruling out there about hiding small items, especially something like lockpicks?

Is language tied to statistics, ability scores, and/or skill proficiencies according to the rules?

While reading this answer to whether or not a druid knows the languages of his/her chosen form, I began to wonder, “What is a language exactly?” Please allow me to walk you through my thought process. I hope these aren’t considered as separate questions so much as things that help clarify my problem.

Is it a skill? I can’t find anything in the PHB or DMG that relates skills and proficiencies to language. In fact, when both are mentioned in a given header, they are never mentioned together as the same thing. I can’t seem to find out how you learn a language, though I’m sure rules exist that might shed light on the issue.

Is it part of the stat block? When creating monsters in the DMG, there is a table for statistics, which doesn’t include ability scores. So I don’t think language is part of the statistics, which would contest the idea that a druid only knows the languages his Wild Shape form knows (see the linked answer above). True Polymorph has similar language to Wild Shape (where this question stems from), and makes no mention of language other than to say you can’t speak unless your new form is capable of speaking. Otherwise, language is either omitted or assumed to be part of creature statistics, ability scores, and/or skills.

Is it related to attribute scores? I’ve heard that things with low intelligence don’t know languages, but I can’t find any proof to back it up. If that were true, perhaps language can be considered to be tied directly to an ability score and therefore not part of the stat block. This would also mean that modifying ability scores could potentially affect language speaking ability as a RAW effect, but might not make sense to change the languages you do know.

Is it part of personality? Feeblemind mentions “Shattering its intellect and personality” by reducing intelligence and charisma scores to 1. Personality is also mentioned in True Polymorph and Wild Shape, which might lend credence to the idea that language is tied to personality OR it might mean it’s tied to ability scores. Feeblemind also specifically mentions that the target can’t understand or speak any language, presumably as a result of intelligence and/or charisma being 1. If language were tied to personality, changing your form wouldn’t affect language as long as you retained your personality.

Is it it’s own thing? Perhaps languages aren’t related to anything and this might mean there is no hard and fast rule regarding what languages are and how they are related to the technical aspects of the game.

So what is a language? Perhaps to get behind this question is to ask “What are the implications of changing your ability scores, statistics, and skills for language?”

Rules for Stranglers

Does anyone have any play-tested house rules for dealing with attempts to strangle a (not helpless) creature to death?

Suffocating, per the rules

As far as I see, the only guidance in the rules would be the PH rules of Suffocating (Chapter 8, page 183) which determine how long a creature can survive without breathing. Unless there’s a strong argument otherwise, I think the best answer would leverage these rules.

Maintaining a strangle?

The main part not covered in the rules would be mechanics on how an attacker achieves and maintains a strangle (with or without a garotting wire) long enough for the suffocation rules to take effect.

The Precipitating Event

I was playing a game where an ad hoc rule was:

(grapple) + (successful strength contest) == (death by strangulation) 

I think this is way overpowered. And would plan on changing tactics so my halfling wizard became a mad strangler if it were allowed going forward.

(It won’t be a problem discussing this with my DM, that’s not what this question is about. I’m interested solutions people might already be using.)

Note on Question Focus

To keep the topic focused, I’m not asking about other breath-related scenarios (“choking out” a target to capture it, holding a victim underwater). A concise answer that incorporated these other cases might be appropriate, especially if it sheds light on this specific case.