fiftyone.device.example.illustration
Class MatchMetrics

java.lang.Object
  extended by fiftyone.device.example.illustration.MatchMetrics
All Implemented Interfaces:
Closeable

public class MatchMetrics
extends Object
implements Closeable

Getting started example of using 51Degrees device detection match metrics information. The example shows how to;

  1. Instantiate 51Degrees detection provider
      
          provider = new Provider(StreamFactory.create(
          Shared.getLitePatternV32(), false));
      
      
  2. Pass in a single HTTP User-Agent header
      
          Match match = provider.match(userAgent);
      
      
  3. Obtain device Id: consists of four components separated by a hyphen symbol: Hardware-Platform-Browser-IsCrawler where each Component is represented an ID of the corresponding Profile.
      
          match.getDeviceId();
      
      
  4. Retrieve match method: provides information about the algorithm that was used to perform detection for a particular User-Agent. For more information on what each method means please see: How device detection works
      
          match.getMethod();
      
      
  5. Get difference: used when detection method is not Exact or None. This is an integer value and the larger the value the less confident the detector is in this result.
      
          match.getDifference();
      
      
  6. Retrieve signature rank: an integer value that indicates how popular the device is. The lower the rank the more popular the signature.
      
          match.getSignature().getRank();
      
      

main assumes it is being run with a working directory at root of project or of this module.


Field Summary
protected  String desktopUserAgent
           
protected  String mediaHubUserAgent
           
protected  String mobileUserAgent
           
protected  Provider provider
           
 
Constructor Summary
MatchMetrics()
          Initialises the device detection Provider with the included Lite data file.
 
Method Summary
 void close()
          Closes the Dataset by releasing data file readers and freeing the data file from locks.
 String getDeviceId(Match match)
          Device ID is a string of four numeric components separated by hyphen.
 int getDifference(Match match)
          Extract the difference value from the Match object provided.
 MatchMethods getMethod(Match match)
          Extracts MatchMethods enumeration value from the Match object.
 int getRank(Match match)
          Extracts the signature rank from the Match object provided.
static void main(String[] args)
          Main entry point for this example.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

provider

protected final Provider provider

mobileUserAgent

protected final String mobileUserAgent
See Also:
Constant Field Values

desktopUserAgent

protected final String desktopUserAgent
See Also:
Constant Field Values

mediaHubUserAgent

protected final String mediaHubUserAgent
See Also:
Constant Field Values
Constructor Detail

MatchMetrics

public MatchMetrics()
             throws IOException
Initialises the device detection Provider with the included Lite data file. For more data see: compare data options

Throws:
IOException - can be thrown if there is a problem reading from the provided data file.
Method Detail

getMethod

public MatchMethods getMethod(Match match)
Extracts MatchMethods enumeration value from the Match object. The extracted value represents the algorithm used to perform this detection.

Match object must be created and populated by invoking the provider.match(userAgentString) before supplying to this method.

Parameters:
match - Match object containing detection results, not null.
Returns:
MatchMethods enumeration used for this detection.

getDifference

public int getDifference(Match match)
Extract the difference value from the Match object provided. Difference represents the level of confidence the detector has in the accuracy of the current detection. The higher the number the less confident the detector is.

Difference value is only relevant to Nearest, Closest and Numeric methods. Exact method will always have a value of zero. Difference is irrelevant to None as the User-Agent that yielded this result is almost certainly fake.

Match object must be created and populated by invoking the provider.match(userAgentString) before supplying to this method.

Parameters:
match - Match object containing detection results, not null.
Returns:
integer value of difference indicating the level of confidence the detector has in the current match results.

getRank

public int getRank(Match match)
            throws IOException
Extracts the signature rank from the Match object provided. Signature rank indicates the relative level of popularity of the given signature. The lower the value the more popular the requesting device is.

Popularity is determined by 51Degrees and is based on our statistics.

Match object must be created and populated by invoking the provider.match(userAgentString) before supplying to this method.

Parameters:
match - Match object containing detection results, not null.
Returns:
integer representing the popularity of the matched device. The lower the number the more popular device is.
Throws:
IOException - if there is a problem accessing the data file.

getDeviceId

public String getDeviceId(Match match)
                   throws IOException
Device ID is a string of four numeric components separated by hyphen. A relevant profile is picked by the detector for each of the following components: Hardware-Platform-Browser-IsCrawler.

Parameters:
match - Match object containing detection results, not null.
Returns:
String with device ID consisting of four profile IDs.
Throws:
IOException - if there is a problem accessing the data file.

main

public static void main(String[] args)
                 throws IOException
Main entry point for this example. For each of the User-Agents defined in this class:
  1. performs detection;
  2. stores detection information in a Match object;
  3. Each Match object is then passed to one of the relevant methods to retrieve match metrics information, i.e.: getDeviceId(fiftyone.mobile.detection.Match) is invoked to return an Id string.

Parameters:
args - command line arguments, not used.
Throws:
IOException - if there is a problem accessing the data file.

close

public void close()
           throws IOException
Closes the Dataset by releasing data file readers and freeing the data file from locks. This method should only be used when the Dataset is no longer required, i.e. when device detection functionality is no longer required, or the data file needs to be freed.

Specified by:
close in interface Closeable
Throws:
IOException - if there is a problem accessing the data file.


Copyright © 2017 51Degrees. All rights reserved.