Comparing the 1971, 2012, and 2013 Egyptian Constitutions

The Comparative Constitutions Project has developed a new tool that allows one to compare the 1971, 2012, and 2013 Egyptian constitutions:  http://comparativeconstitutionsproject.org/comparing-the-egyptian-constitution/.  We have assigned the topics from the Constitute site to the texts of those three constitutions, which allows one to select a topic and see how each of the three constitutions addresses it.  If you are interested in how much (or little) the Egyptian constitution has changed as a result of the Arab Spring, then I encourage you to take a look.

(Please send me an e-mail or make a comment if you notice any errors in our assignment of topics.)

Directly Querying the Constitute Data

Thank you to all who attended my seminar today.  As promised, I am going to provide the code that I used to query the data underlying the Constitute site.

To start, you will need to know how to write a SPARQL query.  There are good resources online to teach you how to write such queries (see here or here).  Once you know a bit about writing SPARQL queries, you can test out your skills on the data underlying the Constitute site.  Just copy and paste your queries here.  To get you started, here are the two queries that I used in my seminar:

Query 1:

PREFIX ontology:<http://tata.csres.utexas.edu:8080/constitute/ontology/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT ?const ?country ?year
WHERE {
?const ontology:isConstitutionOf ?country .
?const ontology:yearEnacted ?year .
}

Query 2:

PREFIX ontology:<http://tata.csres.utexas.edu:8080/constitute/ontology/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT ?const ?country ?year ?region ?sectionType ?sectionText ?childType ?childText
WHERE {
?const ontology:isConstitutionOf ?country .
?const ontology:yearEnacted ?year .
?section ontology:isSectionOf ?const .
?country ontology:isInGroup ?region .
?section ontology:hasTopic ontology:env .
?section ontology:rowType ?sectionType .
OPTIONAL {?section ontology:text ?sectionText}
OPTIONAL {?childSection ontology:parent ?section . ?childSection ontology:text ?childText}
OPTIONAL {?childSection ontology:parent ?section . ?childSection ontology:rowType ?childType}
}

Notice the “topic” line in the second query (?section ontology:hasTopic ontology:env .).  The env part of that line is the tag that we use to indicate provisions that deal with “Protection of environment”.  You can explore the list of topics included on Constitute and their associated tags here.

The next step is to apply your querying knowledge using the SPARQL package in R.  I will demonstrate how this is done by walking you through the creation of the Word Cloud that I discussed during my seminar (the code for the histogram is easier to understand and is below).  First, query the SPARQL endpoint using R:

#Opens the Relevant Libraries
library(SPARQL)
#Defines URL for Endpoint
endpoint <- "http://tata.csres.utexas.edu:8080/openrdf-sesame/repositories/test"
#Defines the Query
query <- "PREFIX ontology:<http://tata.csres.utexas.edu:8080/constitute/ontology/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT ?const ?country ?year ?region ?sectionType ?sectionText ?childType ?childText
WHERE {
?const ontology:isConstitutionOf ?country .
?const ontology:yearEnacted ?year .
?section ontology:isSectionOf ?const .
?country ontology:isInGroup ?region .
?section ontology:hasTopic ontology:env .
?section ontology:rowType ?sectionType .
OPTIONAL {?section ontology:text ?sectionText}
OPTIONAL {?childSection ontology:parent ?section . ?childSection ontology:text ?childText}
OPTIONAL {?childSection ontology:parent ?section . ?childSection ontology:rowType ?childType}
}"

#Queries the endpoint
sparql <- SPARQL(endpoint,query,ns=c('ontology','<http://tata.csres.utexas.edu:8080/constitute/ontology/>','const','<http://tata.csres.utexas.edu:8080/constitute/>'))

You now have a data table with the relevant textual data available to you in R under sparql$results.  The second step is to organize that data into a corpus using the text mining package (tm, for short).  Ultimately, I am only interested in rows in the data table that have text (i.e. the sectoinText and childText columns are not empty) and that are from constitutions written in the Americas or Africa, so I will filter the data along these lines in this step of the process.  Here is the code:

#Opens the Relevant Libraries
library(tm)
library(SnowballC)

#Filters Out Correct Regions
data.Africa <- subset(sparql$results,sparql$results$region=="const:ontology/Africa")
data.Americas <- subset(sparql$results,sparql$results$region=="const:ontology/Americas")

#Extracts Section Text from Results and Removes Missing Values
sText.Africa <- subset(data.Africa,data.Africa$sectionText!='NA')
sText.Africa <- subset(sText.Africa$sectionText,sText.Africa$sectionType=="const:ontology/body")
sText.Americas <- subset(data.Americas,data.Americas$sectionText!='NA')
sText.Americas <- subset(sText.Americas$sectionText,sText.Americas$sectionType=="const:ontology/body")

#Extracts Child Section Text from Results and Removes Missing Values
cText.Africa <- subset(data.Africa,data.Africa$childText!='NA')
cText.Africa <- subset(cText.Africa$childText,cText.Africa$childType=="const:ontology/body")
cText.Americas <- subset(data.Americas,data.Americas$childText!='NA')
cText.Americas <- subset(cText.Americas$childText,cText.Americas$childType=="const:ontology/body")

#Appends Parent and Child Text Together
Text.Africa <- data.frame(c(sText.Africa,cText.Africa))
Text.Americas <- data.frame(c(sText.Americas,cText.Americas))

#Converts Data Frames to Corpora
corpus.Africa <- Corpus(VectorSource(Text.Africa))
corpus.Americas <- Corpus(VectorSource(Text.Americas))

Now that I have organized the relevant text into corpora, I need to clean those corpora by removing stop words (e.g. a, an and the), punctuation and numbers and stemming words.  This is standard practice before analyzing text to prevent “the” from being the largest word in my word cloud and to make sure that “right” and “rights” are not counted separately.  The tm package has all the tools to perform this cleaning.  Here is the code:

#Makes All Characters Lower-Case
corpus.Africa <- tm_map(corpus.Africa,tolower)
corpus.Americas <- tm_map(corpus.Americas,tolower)

#Removes Punctuation
corpus.Africa <- tm_map(corpus.Africa,removePunctuation)
corpus.Americas <- tm_map(corpus.Americas,removePunctuation)

#Removes Numbers
corpus.Africa <- tm_map(corpus.Africa,removeNumbers)
corpus.Americas <- tm_map(corpus.Americas,removeNumbers)

#Removes Stopwords
corpus.Africa <- tm_map(corpus.Africa,removeWords,stopwords('english'))
corpus.Americas <- tm_map(corpus.Americas,removeWords,stopwords('english'))

#Stems Words
dict.corpus.Africa <- corpus.Africa
corpus.Africa <- tm_map(corpus.Africa,stemDocument)
corpus.Africa <- tm_map(corpus.Africa,stemCompletion,dictionary=dict.corpus.Africa)
dict.corpus.Americas <- corpus.Americas
corpus.Americas <- tm_map(corpus.Americas,stemDocument)
corpus.Americas <- tm_map(corpus.Americas,stemCompletion,dictionary=dict.corpus.Americas)

The last step is to analyze the cleaned text.  I created a simple word cloud, but you could perform even more sophisticated text analysis techniques to the textual data on Constitute.  I used the wordcloud package to accomplish this task.  Here is the code I used to create the word clouds for my presentation:

#Opens the Relevant Libraries
library(wordcloud)
library(RColorBrewer)
library(lattice)

#Creates a PNG Document for Saving
png(file="WC_env.png", height = 7.5, width = 14, units = "in", res=600, antialias = "cleartype")

#Sets Layout
layout(matrix(c(1:2), byrow = TRUE, ncol = 2), widths = c(1,1), heights = c(1,1), respect = TRUE)

#Sets Overall Options
par(oma = c(0,0,5,0))

#Selects Colors
pal <- brewer.pal(8,"Greys")
pal <- pal[-(1:3)]

#Word Cloud for the Americas
wordcloud(corpus.Americas,scale=c(3,0.4),max.words=Inf,random.order=FALSE,rot.per=0.20,colors=pal)

#Creates Title for Americas Word Cloud
mtext("Americas",side=3,cex=1.25,line=4)

#Word Cloud for Africa
wordcloud(corpus.Africa,scale=c(3,0.4),max.words=Inf,random.order=FALSE,rot.per=0.20,colors=pal)

#Creates Title for African Word Cloud
mtext("Africa",side=3,cex=1.25,line=4)

#Creates an Overall Title for the Figure
mtext("Constitutional Provisions on the Environment",outer=TRUE,cex=2,font=2,line=1.5)

#Closes the Plot
dev.off()

Note that the plotting commands above are complicated by the fact that I wanted to combine two word clouds into the same image.  Had I only wanted to create a single word cloud, say for Africa, and did not care much about the colors of the plot, the following commands would have sufficed:

#Opens the Relevant Libraries
library(wordcloud)

#Word Cloud for Africa
wordcloud(corpus.Africa,scale=c(3,0.4),max.words=Inf,random.order=FALSE,rot.per=0.20,colors=pal)

Anyway, here is the resulting word cloud:

WordClouds_Env

With the commands above, you should be able to replicate the word clouds from my seminar.  In addition, minor modifications to the commands above will allow you to describe the constitutional provisions on different topics or to compare the way that different regions address certain topics.  One could even perform more advanced analyses of these texts with the SPARQL queries outlined above.

CODE FOR HISTOGRAM

#Opens the Relevant Libraries
library(SPARQL)
library(RColorBrewer)

#Defines URL for Endpoint
endpoint <- "http://tata.csres.utexas.edu:8080/openrdf-sesame/repositories/test"

#Defines the Query
query <- "PREFIX ontology:<http://tata.csres.utexas.edu:8080/constitute/ontology/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT ?const ?country ?year
WHERE {
?const ontology:isConstitutionOf ?country .
?const ontology:yearEnacted ?year .
}"

#Makes the Query
sparql <- SPARQL(endpoint,query,ns=c('ontology','<http://tata.csres.utexas.edu:8080/constitute/ontology/>','const','<http://tata.csres.utexas.edu:8080/constitute/>'))

#Subsets Data
data.year <- data.frame(subset(sparql$results,select=c("const","year")))

#Drops Duplicate Observations
data.year <- unique(data.year)

#Makes Year Numeric
year <- as.numeric(data.year$year)

#Creates PNG Document for Saving
png(file="Histogram_Year.png")

#Selects Colors
pal <- brewer.pal(3,"Greys")
pal <- pal[-(1:2)]

#Histogram Command
hist(year, breaks=21, col = pal, border = pal, xlab = "Promulgation Year", ylab = "Number of Constitutions", ylim = c(0,60), xlim = c(1790,2010), main = "Constitutions on Constitute")

#Closes the Plot
dev.off()

And here it is:

Histogram_Year

What Would a Scottish Constitution Look Like?

Last week, Stephen Tierney posted an excellent evaluation of the White Paper released by the Scottish Government on “Scotland’s Future”.  In his evaluation, Professor Tierney addresses three issues related to the Government’s repeated commitment to write a constitution should Scotland become independent:  1) when will it be finished? 2) what will be in it? and 3) what process will be used to make it?  Much of his post is on the process of writing a Scottish constitution, so I want to make just a couple of additional observations about the likely contents of a Scottish constitution.  My remarks are based on a report that I wrote last spring with my collaborators on the Comparative Constitutions Project.

First, very little is likely to change in Scotland as a result of drafting a constitution.  As we state in our report:

Almost all countries have institutions that pre-date their entrance into the modern state system and the writing of their first constitution.  Regardless of whether a state’s primordial institutions were purely informal rules, as in the earliest states, or colonial structures, they will likely survive in some form.  Institutions inevitably favor some individuals’ interests over others, so those who benefit from the presence of some institution have a strong incentive to fight for the continued existence of that institution during constitutional drafting.  Factors such as colonial heritage, legal origin, religion, ethnic fractionalization, language, and region are strong predictors of pre-state institutions and, as a result, the content of subsequent constitutional systems. (p. 3)

If Scotland becomes independent, regardless of whether it writes a constitution or not, the institutions established by the Scotland Act (1998) are likely to live on and to maintain the same structure and powers that they have today.  As a result, ordinary politics in an independent Scotland are likely to look almost identical to ordinary politics in Scotland today.

I am not suggesting that Scotland should not write a constitution.  The act of writing a constitution has value beyond the contents of the document.  Writing a constitution can help build legitimacy for the new Scottish state and, depending on the process in which it is drafted and promulgated, may even help to unify the newly independent nation.  By establishing a hierarchical system of law, a constitution may even further entrench democracy and the rule of law in Scotland.  What I am suggesting is that, regardless of any positive externalities that Scotland might reap from writing a constitution, the contents of that document are largely predetermined.

Second, I am sceptical of the Government’s promise to entrench socioeconomic rights in the Scottish constitution.  Socioeconomic rights are easy to promise but hard to deliver.  If the Government really intends to deliver on the socioeconomic rights that it has promised, then it should promise to make them justiciable, meaning that the Courts in Scotland will be able to enforce them, and explain how it intends to pay for them.  The Government has done neither.  As a result, I think it is more likely that there will be socioeconomic rights entrenched in the Scottish constitution but that those rights will be aspirational, giving the Government lots of flexibility when deciding whether or not to adhere to those promises.

Will Ministers want an EMO?

Whitehall has a new acronym – the EMO.  Not some exotic bird, but Extended Ministerial Offices, first announced by Francis Maude in July.  Last week Cabinet Office published guidelines fleshing out the details: https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/261358/November_-_EMO_Guidance_to_Departments.pdf

EMOs will have three categories of staff: civil servants in the traditional Private Office role, Special Advisers, and external appointees.  The main expansion is likely to be in the third category, and the Civil Service Commission have created a new exception to allow recruitment without competition of chosen individuals as temporary civil servants for up to five years.  The previous maximum was two years: the new exception will allow outsiders to be recruited for the whole of a Parliament.

Ministers who want an EMO will need first to agree the mix of staff and the budget with their Permanent Secretary, before seeking the approval of the Prime Minister.  The budget must come within the department’s overall allocation.  The main quality control will come from Cabinet Office and the PM’s Chief of Staff in scrutinising EMO proposals: the PM is unlikely to give this his personal attention.  A few Ministers may go up from two Special Advisers to three.  But the main test will lie with the external appointees: will they be additional cheerleaders, or serious policy experts?  No 10 will be alert to negative headlines (eg The Times 19 November) and may be tight in what they allow through.

There are two twists in the tail for Ministers who want an EMO.  The first is that at least one member of the EMO must focus on implementation, reporting to the Head of the Cabinet Office Implementation Unit. So there is a direct line reporting line from the EMO to the centre on whether the department is meeting its targets.  The second is that requests must include ‘specific proposals for strengthening the offices of junior Ministers … of a different party’.  Where no EMO is planned, junior ministers can put forward their own proposals.  This is primarily to strengthen the support for the dozen Lib Dem junior ministers scattered round Whitehall, who feel isolated and outgunned. But it will require courage for them to go it alone: they must discuss their proposals first with their Secretary of State, who may not want to give the Lib Dems additional firepower.

Will many Ministers want an EMO?  In the remainder of this Parliament that seems unlikely.  Maude will have to have one, to set an example; but only a handful of colleagues may follow.  Energetic Ministers like Gove have already found ways of recruiting additional advisers, and may not want to seek approval from the centre.  And outsiders may be reluctant to sign up for an 18 month passage when the ship is beginning to run out of steam and they may be paid off in 2015.  So the real test will be in the next Parliament.  In an interview with Civil Service World Labour’s shadow Cabinet Office  spokesman Jon Trickett said that he supported the government’s plans for EMOs [link – http://www.civilserviceworld.com/trickett-civil-service-reforms-ad-hoc-with-hectoring-tone/].  But that was off the cuff, in the margins of the Labour party conference; we don’t know Miliband’s views.   If we have another hung Parliament, the future of EMOs might depend not on Francis Maude, but on the Lib Dems carrying his idea into the next government if they hold the balance of power.