<commit_before>{-# LANGUAGE OverloadedStrings #-}

module Y2020.M10.D28.Exercise where

{--
I collected the military alliances of the world, and their member-nations, with
the following SPARQL query to wikidata.org:

# Military alliances
SELECT ?alliance ?allianceLabel ?country ?countryLabel ?memberOf
WHERE 
{
  ?alliance wdt:P31 wd:Q1127126.
  ?country wdt:P31 wd:Q6256.
  ?country ?memberOf ?alliance.
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
  }
}

We also have alliances in opposition:

# alliances and oppositions
SELECT ?alliance1 ?alliance1Label ?alliance2 ?alliance2Label
WHERE 
{
  ?alliance1 wdt:P31 wd:Q1127126.
  ?alliance1 wdt:P461 ?alliance2.
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
  }
}

but that result-set is rather underwhelming, should you care to look.

The military alliances and their member countries, and the oppositions
are stored in JSON files in this directory. Read in these JSONs in the data
structures declared below, then answer the questions following.
--}

import Y2020.M10.D12.Exercise   -- for Country

import Data.Aeson
import Data.ByteString.Lazy.Char8 (ByteString)

import Data.Set (Set)
import Data.Text (Text)

deer :: FilePath   -- ... geddit?
deer = "Y2020/M10/D28/"

alliancesFile :: FilePath
alliancesFile = "military-alliances.json"

-- okay, we need some structure for the above, yes?

type Qname = Text
type Name = Text

data WikiDatum = WD { qid :: Qname, name :: Name }
   deriving (Eq, Ord, Show)

instance FromJSON WikiDatum where
   parseJSON = undefined

data AllianceMember = AllianceMember { alliance :: WikiDatum,
                                       country :: WikiDatum }
   deriving (Eq, Ord, Show)

instance FromJSON AllianceMember where
   parseJSON = undefined

-- also, please filter out the (one) alliance that does not have membership
-- value the same as all the other members (that's an indirect hint that
-- `memberOf` isn't always a `memberOf`-property).

allianceMembers :: ByteString -> [AllianceMember]
allianceMembers = undefined
<commit_msg>Backfilled typing for WikiDatum<commit_after>{-# LANGUAGE OverloadedStrings #-}

module Y2020.M10.D28.Exercise where

{--
I collected the military alliances of the world, and their member-nations, with
the following SPARQL query to wikidata.org:

# Military alliances
SELECT ?alliance ?allianceLabel ?country ?countryLabel ?memberOf
WHERE 
{
  ?alliance wdt:P31 wd:Q1127126.
  ?country wdt:P31 wd:Q6256.
  ?country ?memberOf ?alliance.
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
  }
}

We also have alliances in opposition:

# alliances and oppositions
SELECT ?alliance1 ?alliance1Label ?alliance2 ?alliance2Label
WHERE 
{
  ?alliance1 wdt:P31 wd:Q1127126.
  ?alliance1 wdt:P461 ?alliance2.
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
  }
}

but that result-set is rather underwhelming, should you care to look.

The military alliances and their member countries, and the oppositions
are stored in JSON files in this directory. Read in these JSONs in the data
structures declared below, then answer the questions following.
--}

import Y2020.M10.D12.Exercise   -- for Country

import Data.Aeson
import Data.ByteString.Lazy.Char8 (ByteString)

import Data.Set (Set)
import Data.Text (Text)

deer :: FilePath   -- ... geddit?
deer = "Y2020/M10/D28/"

alliancesFile :: FilePath
alliancesFile = "military-alliances.json"

-- okay, we need some structure for the above, yes?

type Qname = Text
type Name = Text

data WikiDatum = WD { label :: Text, qid :: Qname, name :: Name }
   deriving (Eq, Ord, Show)

-- this is a ... 'little' (?) tricky, because we need to parse a datum by
-- its labels.

instance FromJSON WikiDatum where
   parseJSON = undefined

data AllianceMember = AllianceMember { alliance :: WikiDatum,
                                       country :: WikiDatum }
   deriving (Eq, Ord, Show)

instance FromJSON AllianceMember where
   parseJSON = undefined

-- also, please filter out the (one) alliance that does not have membership
-- value the same as all the other members (that's an indirect hint that
-- `memberOf` isn't always a `memberOf`-property).

allianceMembers :: ByteString -> [AllianceMember]
allianceMembers = undefined

{'fraction_non_alphanumeric': 0.08890420399724328, 'fraction_numerical': 0.027107741787273144, 'mean_word_length': 3.919774011299435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3855394', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1364, 'n_words': 470}