Git Product home page Git Product logo

gpc-tree's Introduction

Gpc-tree

build codecov Current Version Scala Steward badge license

Gpc-tree is a library to work with the Google product categories / taxonomy in a tree structure where every node in the tree consists of a placement in the Google Product Taxonomy and its children (if there are any). It can load any of the available lists of Google product categories and has methods to:

  • find a node in the tree
  • find the parent of a node
  • find the path of a node
  • find the common ancestors between nodes
  • reconstruct a line in the taxonomy file

Installation

Gpc-tree is published for Scala 2.13. To start using it add the following to your build.sbt:

libraryDependencies += "nl.gn0s1s" %% "gpc-tree" % "0.0.1"

Example usage

import java.nio.charset.StandardCharsets

import nl.gn0s1s.gpctree.GpcTree

val gpcTree = new GpcTree(scala.io.Source.fromURL("https://www.google.com/basepages/producttype/taxonomy-with-ids.nl-NL.txt", StandardCharsets.UTF_8.toString))

gpcTree.findNodeInTree("6975") // res0: Option[nl.gn0s1s.Node] = Some(Node(Placement(6975,Biochemicaliën),List()))

gpcTree.findNodeInTree("500105").map(gpcTree.asString) // res1: Option[String] = Some(500105 - Eten, drinken en tabak > Voedselitems > Specerijen en sauzen > Witte en roomsauzen)

// find siblings of a node
gpcTree.findParentInTree("500105").map(_.children) // res2: Option[scala.collection.Seq[nl.gn0s1s.Node]] = Some(List(Node(Placement(6772,Cocktailsaus),List()), Node(Placement(6905,Currysaus),List()), Node(Placement(6845,Dessertsauzen),List(Node(Placement(6854,Fruittoppings),List()), Node(Placement(6844,Siropen voor ijs),List()))), Node(Placement(4947,Honing),List()), Node(Placement(4614,Hot sauce),List()), Node(Placement(500076,Ingelegde vruchten en groenten),List()), Node(Placement(5762,Jus),List()), Node(Placement(2018,Ketchup),List()), Node(Placement(500074,Marinades en grillsauzen),List()), Node(Placement(1568,Mayonaise),List()), Node(Placement(6782,Mierikswortelsaus),List()), Node(Placement(1387,Mosterd),List()), Node(Placement(5760,Olijven en kappertjes),List()), Node(Placement(5759,Pastasauzen),List()),...

Resources

License

The code is available under the Mozilla Public License, version 2.0.

gpc-tree's People

Contributors

philippus avatar scala-steward avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

scala-steward

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.