"The crux of the original parser--the data collected by Steve Souders over the years--has been extracted into a separate YAML file so as to be reusable as is by implementations in other programming languages."
UAParser is a limited Julia implementation heavily influenced by the Python code from the ua-parser library.
New regexes have were retrieved from here on 2018-12-19.
The API for UAParser revolves around three functions:
parseuseragent. Each function takes one argument,
user_agent_string::AbstractString and returns a custom Julia type:
UAResult. The structure of each type is as follows:
DeviceResult: family, brand, model UAResult: family, major, minor, patch OSResult: family, major, minor, patch, patch_minor
using UAParser #Example user-agent string user_agent_string = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3" #Get device from user-agent string parsedevice(user_agent_string) #> DeviceResult("iPhone", "Apple", "iPhone") #Get browser information from user-agent string parseuseragent(user_agent_string) #> UAResult("Mobile Safari","5","1",missing) #Get os information parseos(user_agent_string) #> OSResult("iOS","5","1",missing,missing)
You can index into the results of these functions like any other Julia composite type.
#Get just browser information, no version information x1 = parseuseragent(user_agent_string) x1.family #> "Mobile Safari" #Get the os, no version information x2 = parseos(user_agent_string) x2.family #> "iOS"
A Note On Parser Accuracy
When this library was created, it became very obvious that it would be hard to replicate the Python parser code with 100% accuracy. The authors decided that a reasonably accurate implementation was more useful than spending the time to achieve 100% accuracy.
The tests in this library test against the accuracy of the parser. As of v0.6 of this package, here are the accuracy statistics against the files provided by the main ua-core project:
parse_device: 15144/16017 (94.6%) parse_os: 1517/1528 (99.3%) parse_ua: 204/205 (99.5%)
Of course, if someone would like to achieve 100% accuracy, PRs will absolutely be reviewed.
The licensing of the UAParser Julia module is under the default MIT Expat license. The data contained in regexes.yaml is Copyright 2009 Google Inc. and available under the Apache License, Version 2.0.