microtesia
package microtesia
Documentation for the Microtesia microdata parsing library.
Usage
To use simply put the Microtesia API in scope and call the parseMicrodata function as follows:
scala> import microtesia._ import microtesia. scala> import scala.util.Try import scala.util.Try scala> parseMicrodata("""<div itemscope itemtype="http://schema.org/Movie"><h1 itemprop="name">Avatar</h1></div>""") res0: Try[microtesia.MicrodataDocument] = Success(MicrodataDocument(List(MicrodataItem(ArrayBuffer((name,MicrodataString(Avatar))),Some(http://schema.org/Movie),None))))
- Alphabetic
- By Inheritance
- microtesia
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
case class
InvalidMicrodata extends Exception with Product with Serializable
Represents failure to parse microdata document, including the line and column number of the failing HTML element.
-
case class
MicrodataDocument extends Product with Serializable
Representation of a document containing microdata mark-up.
Representation of a document containing microdata mark-up. Returned by the parseMicrodata function. A MicrodataDocument can contain multiple MicrodataItem instances which can be accessed via the
rootItems
property as follows:scala> document.rootItems.foreach{ (m: MicrodataItem) => println(m.itemtype) } Some(http://schema.org/Movie)
-
case class
MicrodataItem(properties: Seq[MicrodataProperty], itemtype: Option[URI] = None, id: Option[URI] = None) extends MicrodataValue with MicrodataQuery with Product with Serializable
Represents a microdata "item".
Represents a microdata "item". An item consists of a set of properties (name-value pairs) and an optional itemtype and unique id.
Note Properties are represented by a sequence of MicrodataProperty and not a map as a property name can have multiple values in a microdata document.
- properties
Map of name-value pairs.
- itemtype
Optional type of the item defined by a
URI
.- id
Optional unique identifier of the item defined by a
URI
.
-
case class
MicrodataLink(link: URI) extends MicrodataValue with Product with Serializable
Represents a microdata link value.
-
type
MicrodataProperty = (String, MicrodataValue)
Represents a microdata name-value pair.
-
trait
MicrodataQuery extends AnyRef
Provides support for XPath-like microdata querying.
-
case class
MicrodataString(value: String) extends MicrodataValue with Product with Serializable
Represents a microdata string value.
-
sealed
trait
MicrodataValue extends AnyRef
Generic microdata value.
Generic microdata value. You can extract microdata values using for-comprehensions:
scala> import microtesia._ import microtesia._ scala> val items = List(MicrodataItem(List(MicrodataProperty("name",MicrodataString("Avatar"))))) items: List[microtesia.MicrodataItem] = List(MicrodataItem(List((name,MicrodataString(Avatar))),None,None)) scala> for { MicrodataItem(properties, _, _) <- items MicrodataProperty("name", MicrodataString(string)) <- properties } yield string res0: Seq[String] = List(Avatar)
Value Members
-
def
parseMicrodata(input: InputStream)(implicit c: ExecutionContext): Future[MicrodataDocument]
Parses HTML and returns a structured representation of the microdata items in the document.
Parses HTML and returns a structured representation of the microdata items in the document. If there was an error parsing the microdata it returns a
Left[InvalidMicrodata]
. -
def
parseMicrodata(html: String): Try[MicrodataDocument]
Parses HTML and returns a structured representation of the microdata items in the document.
Parses HTML and returns a structured representation of the microdata items in the document. If there was an error parsing the microdata it returns a
Failed(InvalidMicrodata)
. -
object
MicrodataProperty
Utility object to help extract microdata property values in for-comprehensions.