Skip to content
Yin Qu (屈垠) edited this page Jul 24, 2015 · 7 revisions

BigSemantics 2.0 in JavaScript

Note: Currently, officially we only support Chrome.

Basic Usage

Assuming that your application wants to use the BigSemantics Web Service to extract semantic information:

var bs = new BSService();
bs.onReady(function(err, bs) {
  if (err) {
    console.warn("Cannot initialize BigSemantics: %O", err);
    return;
  }

  var url = "http://www.amazon.com/gp/product/B00I8BIBCW/";
  var options = {};
  bs.loadMetadata(url, options, function(err, result) {
    if (err) {
      console.warn("Failed to load metadata: %O", err);
      return;
    }

    var metadata = result.metadata;
    var mmd = result.mmd;
    console.log("Metadata received: %O", metadata);
    console.log("Accompanying meta-metadata: %O", mmd);
  });
});

Interface IBigSemantics

Clients interact with different implementations of the IBigSemantics interface to use the core functionalities of BigSemantics, including metadata extraction and meta-metadata lookup. There are different implementations of the IBigSemantics interface for different use cases.

The IBigSemantics interface contains the following methods:

isReady()

Returns a boolean value indicating if the implementation has done initialization (including repository loading) and is ready for use.

onReady(callback)

Calls callback when the implementation is ready for use. Parameters of callback:

  • err: Error object if error happens during initialization. Otherwise null.
  • bigsemantics: The IBigSemantics implementation ready for use. If error happened during initialization, null.

loadMetadata(location, options, callback)

Loads semantics information (or ''metadata'') from document indicated by location, and calls callback with results. Parameters:

  • location: The URL of the target document.
  • options: An object containing additional options. Currently supported options:
    • mmd: An prepared meta-metadata object which will be used for extraction. This skips the normal meta-metadata lookup process.
    • mmdName: A meta-metadata name. The meta-metadata object with this name will be looked up in the repository, and used for extraction. This skips the normal meta-metadata lookup process.
  • callback: Callback function to receive results. Parameters:
    • err: Error object. null if no errors happened.
    • result: An object containing both metadata and corresponding meta-metadata, in two fields metadata and mmd respectively. null if errors happened.

loadMmd(name, options, callback)

Loads meta-metadata with specified name from repository, and calls callback with result. Parameters:

  • name: The name of the meta-metadata type.
  • options: An object containing additional options. No specific options supported right now.
  • callback: Callback function to receive results. Parameters:
    • err: Error object. null if no errors happened.
    • mmd: The result meta-metadata. null if errors happened.

selectMmd(location, options, callback)

Looks up meta-metadata for specified location using the selector mechanism, and calls callback with result. Note that if there isn't a meta-metadata specifically authored for the target document, a generic meta-metadata (usually rich_document) will be used. Parameters:

  • location: The URL of the target document.
  • options: An object containing additional options. No specific options supported right now.
  • callback: Callback function to receive results. Parameters:
    • err: Error object. null if no errors happened.
    • mmd: The result meta-metadata. null if errors happened.

canonicalizeLocation(location, options, callback)

Reports the ''canonical'' form of the specified location using the location filter mechanism, through callback. The canonical form aims to provide a unique identifier for a document by removing session tracking parameters, anchors, and other parts from the original URL.

Note: by default, this method does not actually connect to the target document, thus does not handle redirections. The result is supposed to be an initial guess, usually used for hinting the type of many outlinks.

Parameters:

  • location: The URL to be canonicalized
  • options: An object containing additional options. No specific options supported right now.
  • callback: Callback function to receive results. Parameters:
    • err: Error object. null if no errors happened.
    • canonicalLocation: The result canonical location. null if errors happened.
Clone this wiki locally