Skip to content

Instantly share code, notes, and snippets.

@tom-sherman
Last active March 6, 2019 16:27
Show Gist options
  • Save tom-sherman/da4be2814ce2edfd07c66e84af8d87b5 to your computer and use it in GitHub Desktop.
Save tom-sherman/da4be2814ce2edfd07c66e84af8d87b5 to your computer and use it in GitHub Desktop.
Rainbird xq / jq cookbook

Rainbird xq Cookbook

Installation

  1. Follow this guide to install jq
  2. Install Python and pip if you haven't already
  3. Install yq via pip by running pip install yq

Recipes

For the following recipes we will assume we have a map called map.xml in our current working directory.

View all relationships, concepts, concept instances, relinsts

Concepts

cat map.xml | xq '."rbl:kb".concept'

Relationships

cat map.xml | xq '."rbl:kb".rel'

Concept instances (concinst)

cat map.xml | xq '."rbl:kb".concinst'

Relationship instances (relinst)

cat map.xml | xq '."rbl:kb".relinst'

Get all facts

Facts are just conditionless relinst tags.

cat map.xml | xq '."rbl:kb".relinst | map(select(.condition == null))'

Get all concept instance values of a certain type.

The following gets all Country instances from the map.

cat map.xml | xq -r '."rbl:kb".concinst | .[] | select(."@type"=="Country")."@name"'

Get all relationships with second form object question wordings

cat map.xml | xq '."rbl:kb".rel | map(select(.secondFormObject != null))'

Create CSV of relationships with rel name, subject, object, and second form object question wordings

cat map.xml | xq '."rbl:kb".rel | map(select(.secondFormObject != null)) | map([ ."@name", ."@subject", "@object", .secondFormObject ]) | .[] | @csv'

Count how many relationships with question wordings

cat map.xml | xq '."rbl:kb".rel | map(select(.secondFormObject != null or .secondFormSubject != null or .firstForm != null)) | length'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment