Web device classification from user agent strings
Haskell C
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Tests
Web/Device
cbits
dClass @ bfbf34f
.gitignore
.gitmodules
LICENSE
README.markdown
Setup.hs
phew.cabal

README.markdown

Phew: Fast Web Device Classification

Phew is a Haskell library for quickly gleaning device characteristics from User-Agent strings. It owes all of its speed to the dClass engine by the folks at The Weather Channel. Refer to the README in the dClass repository for more on its internals and performance characteristics.

Usage

There are two functions exposed: loadFile and classify. loadFile takes the path to a dtree file as an argument and returns an Index for classification. classify takes the Index and a User-Agent string as arguments and returns a Map of device attributes.

Example

To get a basic idea of the usage:

import Web.Device.Phew

...

ua :: Text
ua = "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; PJ83100/2.20.502.7\
    \ Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile\
    \ Safari/534.30"

...

Just index <- loadFile "dClass/dtrees/openddr.dtree"
let attrMap = classify index ua
print attrMap

The attrMap is a Map; printing it would look like (sans formatting)

fromList [
    ("ajax_support_javascript","true"),
    ("device_os","Android"),
    ("displayHeight","1280"),
    ("displayWidth","720"),
    ("inputDevices","touchscreen"),
    ("is_crawler","false"),
    ("is_tablet","false"),
    ("is_wireless_device","true"),
    ("model","S720e"),
    ("parentId","genericHTC"),
    ("vendor","HTC")
]