I'm completely lost here. Any tips? Maybe somebody has experience working with other UA parsing libraries?

Hi Andrii,
I have used the same library you are attempting to use in the past and it has worked well. My needs were simple and I found the bitwalker lib to be a great library for those needs. Here is working code showing how I used it (note, you can get more data from it but I was only interested in a subset):

(ns rbl.feature-extraction.user-agent
  (:use [clojure.core.memoize :only [memo]])
  (:require [clojure.tools.logging :as log])
  (:import [nl.bitwalker.useragentutils UserAgent DeviceType Browser 
OperatingSystem]))

(defn str->features [string]
  (try
    (let [user-agent (UserAgent. (or string ""))]
      {:browser_group (-> user-agent .getBrowser .getGroup .getName)
       :os_group (-> user-agent .getOperatingSystem .getGroup .getName)
       :device_type (-> user-agent .getOperatingSystem .getDeviceType 
.getName)})
    (catch Exception e
      (log/error (str "Could not derive the user-agent from " string) e)
      (str->features nil))))

(def possible-features
  (memo (fn []
          {:os_group (set (map #(-> % .getGroup .getName) 
(OperatingSystem/values)))
           :browser_group (set (map #(-> % .getGroup .getName) 
(Browser/values)))
           :device_type (set (map #(.getName %) (DeviceType/values)))})))


In gist form along with some midje facts: https://gist.github.com/3946906


Hope that helps,

Ben



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to