Giter VIP home page Giter VIP logo

Comments (15)

mrjgreen avatar mrjgreen commented on August 20, 2024

Well spotted - this is interesting. There doesn't seem to be anything in the user agents I'm seeing that could qualify as a model, but setting model_replacement to blank/null or leaving unspecified causes the tests to fail. The tests do pass with the model_replacement set as '$3' so perhaps if other implementations fail in the case of unspecified capture groups being used, then we should implement that same failure in the npm tests for the core.

Does anyone have any suggestions on what this should be set as?

Currently we have the following, which as @russellwhitaker pointed out is clearly not correct:

  - regex: '(HbbTV)/1\.1\.1.*CE-HTML/1\.\d;Vendor/(THOMSON);'
    device_replacement: '$1'
    brand_replacement: 'Thomson'
    model_replacement: '$3'

I'm not sure I understand your second point about the rationalisation of "THOMSON". Are you saying you would prefer to see "THOMSON" in the result, rather than "Thomson"?

from uap-core.

russellwhitaker avatar russellwhitaker commented on August 20, 2024

Thanks for the quick followup @mrjgreen . By "rationalisation" I meant this: if the (apparent) intent of the off-by-one reference to the last capture group was to set model_replacement to "THOMSON", does it make sense to then have brand_replacement set to "Thomson" as in this case? I'm not arguing for or against any particular choice, I'm simply wondering what the heuristic is for populating these values. I find it odd that the brand value would be hardcoded here, when it's derivable from capture group 2.

Of course, "THOMSON" or "Thomson" for the value of model, when it's clearly the vendor, doesn't seem right.

from uap-core.

mrjgreen avatar mrjgreen commented on August 20, 2024

Okay I think I see what you mean. No it isn't an off by one error. The parsed values are correct. The error is simply that model_replacement should be blank rather than '$3'.

The brand is correctly identifying as "Thomson".

from uap-core.

russellwhitaker avatar russellwhitaker commented on August 20, 2024

@mrjgreen OK good, shall I generate the PR or did you want to do the honors?

from uap-core.

mrjgreen avatar mrjgreen commented on August 20, 2024

I would do, but it seems that leaving the model_replacement blank or unspecified the tests fail, and I've not had a good chance to sit and look at it yet.

I'm happy for you to give it a go and submit the PR if you manage to get it passing! :)

from uap-core.

russellwhitaker avatar russellwhitaker commented on August 20, 2024

@mrjgreen did you modify all 3 affected tests? Exploring the device tests - there are 15,933 so far - I see:

uap-clj.core=> (def tests-device (:test_cases
          #_=>   (parse-string
          #_=>     (slurp ".lein-git-deps/uap-core/tests/test_device.yaml"))))
#'uap-clj.core/tests-device

uap-clj.core=> (pprint (filter #(re-matches #"(?i).*THOMSON.*" (:user_agent_string %)) tests-device))
({:user_agent_string
  "Opera/9.80 (Linux armv7l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOMSON;SW-Version/V8-MT51F01-LF1V325;Cnt/HRV;Lan/swe; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0) Presto/2.12.362 Version/12.11",
  :family "HbbTV",
  :brand "Thomson",
  :model nil}
 {:user_agent_string
  "Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V394; en) Presto/2.10.250 Version/11.60",
  :family "HbbTV",
  :brand "THOMSON",
  :model "LF1V394"}
 {:user_agent_string
  "Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V401; en) Presto/2.10.250 Version/11.60",
  :family "HbbTV",
  :brand "THOMSON",
  :model "LF1V401"})
nil

uap-clj.core=> (def regexes-all (parse-string (slurp (clojure.java.io/resource "regexes.yaml"))))
#'uap-clj.core/regexes-all

uap-clj.core=> (def regexes-device (:device_parsers regexes-all))
#'uap-clj.core/regexes-device

uap-clj.core=> (pprint (filter #(re-matches #"(?i).*THOMSON.*" (:regex %)) regexes-device))
({:regex "(HbbTV)/1\\.1\\.1.*CE-HTML/1\\.\\d;Vendor/(THOMSON);",
  :device_replacement "$1",
  :brand_replacement "Thomson",
  :model_replacement "$3"})
nil
uap-clj.core=>

All 3 tests should actually be failing.

from uap-core.

russellwhitaker avatar russellwhitaker commented on August 20, 2024

OK, I have a candidate regex:

(HbbTV)/1\.1\.1.*CE-HTML/1\.\d;(Vendor/)*(THOMSON)\s*(LF1V\d+)*;

I'm able to match against the 3 "HbbTV plus Thomson" examples in the devices test yaml set:

uap-clj.core=> (pprint thomson-tests)
({:user_agent_string
  "Opera/9.80 (Linux armv7l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOMSON;SW-Version/V8-MT51F01-LF1V325;Cnt/HRV;Lan/swe; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0) Presto/2.12.362 Version/12.11",
  :family "HbbTV",
  :brand "Thomson",
  :model nil}
 {:user_agent_string
  "Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V394; en) Presto/2.10.250 Version/11.60",
  :family "HbbTV",
  :brand "THOMSON",
  :model "LF1V394"}
 {:user_agent_string
  "Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V401; en) Presto/2.10.250 Version/11.60",
  :family "HbbTV",
  :brand "THOMSON",
  :model "LF1V401"})
nil

uap-clj.core=> (def thomson-regex #"(HbbTV)/1\.1\.1.*CE-HTML/1\.\d;(Vendor/)*(THOMSON)\s*(LF1V\d+)*;")
#'uap-clj.core/thomson-regex

uap-clj.core=> (re-find thomson-regex (:user_agent_string (first thomson-tests)))
["HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOMSON;" "HbbTV" "Vendor/" "THOMSON" nil]
uap-clj.core=> (re-find thomson-regex (:user_agent_string (second thomson-tests)))
["HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V394;" "HbbTV" nil "THOMSON" "LF1V394"]
uap-clj.core=> (re-find thomson-regex (:user_agent_string (last thomson-tests)))
["HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V401;" "HbbTV" nil "THOMSON" "LF1V401"]
uap-clj.core=>

My suggestion for the affected regexes.yaml entry is to discard $2 and use $1 for family, $3 for brand, and $4 for model. What do you think @mrjgreen ? If this looks reasonable to you, I'll generate a PR - I've already forked the repo - and see if Travis is happy with the candidate.

from uap-core.

mrjgreen avatar mrjgreen commented on August 20, 2024

Nice! This looks pretty good to me if the tests pass.

Cheers for sorting this out, and sorry I missed it in the first place!

from uap-core.

commenthol avatar commenthol commented on August 20, 2024

Hi, what about this one?

    - regex: '(HbbTV)/1\.1\.1.*CE-HTML/1\.\d;Vendor/(THOM[^;]*);(?:.*SW-Version/.*(LF[^;]+);)?'
      device_repacement: '$1'
      brand_repacement: 'Thomson'
      model_repacement: '$3'

This even catches

Opera/9.80 (Linux armv7l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOM;SW-Version/V8-MT51F01-LF1V307;Cnt/DEU;Lan/bul) Presto/2.12.362 Version/12.11

from uap-core.

russellwhitaker avatar russellwhitaker commented on August 20, 2024

@commenthol that regex does catch your own example, which isn't yet in test_device.yaml - I will add it there - and also the first HbbTV/Thomson example:

uap-clj.core=> (def alt-regex #"(HbbTV)/1\.1\.1.*CE-HTML/1\.\d;Vendor/(THOM[^;]*);(?:.*SW-Version/.*(LF[^;]+);)?")
#'uap-clj.core/alt-regex

uap-clj.core=> (re-find alt-regex (:user_agent_string (first thomson-tests)))
["HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOMSON;SW-Version/V8-MT51F01-LF1V325;" "HbbTV" "THOMSON" "LF1V325"]

uap-clj.core=> (re-find alt-regex "Opera/9.80 (Linux armv7l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOM;SW-Version/V8-MT51F01-LF1V307;Cnt/DEU;Lan/bul) Presto/2.12.362 Version/12.11")
["HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOM;SW-Version/V8-MT51F01-LF1V307;" "HbbTV" "THOM" "LF1V307"]

It fails for the other two test_device.yaml examples however:

uap-clj.core=> (re-find alt-regex (:user_agent_string (second thomson-tests)))
nil
uap-clj.core=> (:user_agent_string (second thomson-tests))
"Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V394; en) Presto/2.10.250 Version/11.60"

uap-clj.core=> (re-find alt-regex (:user_agent_string (last thomson-tests)))
nil
uap-clj.core=> (:user_agent_string (last thomson-tests))
"Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V401; en) Presto/2.10.250 Version/11.60"

I propose using my alternate regex to catch these two (per yesterday's suggestion) and yours to catch the other two. In all 4 cases, for regularity, we'll set brand_replacement to 'Thomson'.

from uap-core.

russellwhitaker avatar russellwhitaker commented on August 20, 2024

@commenthol please modify my "there are 3 existing test_devices examples plus yours" observation, because "there are 4 existing test_devices examples plus yours":

uap-clj.core=> (pprint (filter #(re-matches #"(?i).*THOM.*" (:user_agent_string %)) tests-device))
({:user_agent_string
  "Opera/9.80 (Linux armv7l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOMSON;SW-Version/V8-MT51F01-LF1V325;Cnt/HRV;Lan/swe; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0) Presto/2.12.362 Version/12.11",
  :family "HbbTV",
  :brand "Thomson",
  :model nil}
 {:user_agent_string
  "Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOM LF1V373; en) Presto/2.10.250 Version/11.60",
  :family "HbbTV",
  :brand "THOM",
  :model "LF1V373"}
 {:user_agent_string
  "Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V394; en) Presto/2.10.250 Version/11.60",
  :family "HbbTV",
  :brand "THOMSON",
  :model "LF1V394"}
 {:user_agent_string
  "Opera/9.80 (Linux armv6l; U; NETRANGEMMH;HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V401; en) Presto/2.10.250 Version/11.60",
  :family "HbbTV",
  :brand "THOMSON",
  :model "LF1V401"})
nil

I'll still use the same approach I mentioned in my previous comment, but will take account of the facts of "THOM number" and "THOMSON number" we're seeing so far.

from uap-core.

russellwhitaker avatar russellwhitaker commented on August 20, 2024

Ah, but wait, there's more! OK, so I've modified a version of @commenthol 's suggested regex which covers all 5 cases itself, no need for a second regex:

(HbbTV)/1\.1\.1.*CE-HTML/1\.\d;(Vendor/)*(THOM[^;]*?)[;\s](?:.*SW-Version/.*)*(LF[^;]+);?

So:

uap-clj.core=> (def one-true-regex #"(HbbTV)/1\.1\.1.*CE-HTML/1\.\d;(Vendor/)*(THOM[^;]*?)[;\s](?:.*SW-Version/.*)*(LF[^;]+);?")
#'uap-clj.core/one-true-regex
uap-clj.core=> (re-find one-true-regex (:user_agent_string (nth tests-thomson 0)))
["HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOM;SW-Version/V8-MT51F01-LF1V307;" "HbbTV" "Vendor/" "THOM" "LF1V307"]
uap-clj.core=> (re-find one-true-regex (:user_agent_string (nth tests-thomson 1)))
["HbbTV/1.1.1;CE-HTML/1.0;Vendor/THOMSON;SW-Version/V8-MT51F01-LF1V325;" "HbbTV" "Vendor/" "THOMSON" "LF1V325"]
uap-clj.core=> (re-find one-true-regex (:user_agent_string (nth tests-thomson 2)))
["HbbTV/1.1.1;CE-HTML/1.0;THOM LF1V373;" "HbbTV" nil "THOM" "LF1V373"]
uap-clj.core=> (re-find one-true-regex (:user_agent_string (nth tests-thomson 3)))
["HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V394;" "HbbTV" nil "THOMSON" "LF1V394"]
uap-clj.core=> (re-find one-true-regex (:user_agent_string (nth tests-thomson 4)))
["HbbTV/1.1.1;CE-HTML/1.0;THOMSON LF1V401;" "HbbTV" nil "THOMSON" "LF1V401"]

Here's the latest suggested entry in regexes.yaml:

  - regex: '(HbbTV)/1\.1\.1.*CE-HTML/1\.\d;(Vendor/)*(THOM[^;]*?)[;\s](?:.*SW-Version/.*)*(LF[^;]+);?'
    device_replacement: '$1'
    brand_replacement: 'Thomson'
    model_replacement: '$4'

OK, this is the one I'll include in the PR I've been promising. Really.

from uap-core.

commenthol avatar commenthol commented on August 20, 2024

Thanks.

from uap-core.

russellwhitaker avatar russellwhitaker commented on August 20, 2024

Done: #53

from uap-core.

mrjgreen avatar mrjgreen commented on August 20, 2024

Nice one guys!

from uap-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.