Most developers in HackUPC were not familiar with the Wolfram Language and they were using other programming languages (i.e. Python, JavaScritpt, ...). And of course, they were not aware that the Wolfram Language can be fully integrated into their projects.
So, I started by showing them how easy is to embed WL code into other programming languages using the EmbedCode Function. I created an APIFunction using ImageIdentify as an example:
APIFunction[{"image" -> "Image"}, ImageIdentify[#image] &]
Then I deployed to the Wolfram cloud with CloudDeploy and finally I specified the programming language to which embed the WL code (Python in this particular case):
EmbedCode[ CloudDeploy[APIFunction[{"image" -> "Image"}, ImageIdentify[#image] &], Permissions -> "Public"], "Python"]
The result is the following Python code:
from urllib import urlencode
from urllib2 import urlopen
class WolframCloud:
def wolfram_cloud_call(self, **args):
arguments = dict([(key, arg) for key, arg in args.iteritems()])
result = urlopen("http://www.wolframcloud.com/objects/e9a0e41f-120a-4d54-925a-835108932f", urlencode(arguments))
return result.read()
def call(self, image):
textresult = self.wolfram_cloud_call(image=image)
return textresult
And now the API can be called easily using Python, for example sending the following picture of a dog to our API gives a "Labrador retriever" as a result:
a = WolframCloud()
result = a.call('https://www.petfinder.com/wp-content/uploads/2012/11/dog-how-to-select-your-new-best-friend-thinkstock99062463.jpg')
print(result)
After explaining how to do this it was straightforward for the HackUPC teams to implement the Wolfram Language into their projects.
For example the team winning the Best Use of Wolfram Tech Award: DriveFlyTeleport! Sightseeing: The Smart Way used the Wolfram Language to get data from Wikipedia with WikipediaData Function of the most touristic places in Barcelona and then create Jaccard Indices with the Wikipedia data and the user twitter account text information, in order to guess the preference of the user on what to visit first:
jaccard[a_, b_] := ( c = Length[Union[a, b]]; d = Length[Intersection[a, b]]; d / c )
listOfWords[topic_] := (
wikipediaData = WikipediaData[topic];
wikiList = StringSplit[wikipediaData, Except[WordCharacter]..];
wikiListLower = Map[ToLowerCase, wikiList];
stopWords = WordData[All, "Stopwords"];
lowerNoStopWords = Select[wikiListLower, Not[MemberQ[stopWords, #]] &];
lowerNoStopWords
)
cleanWords[s_] := (
wikiList = StringSplit[s, Except[WordCharacter]..];
listLower = Map[ToLowerCase, wikiList];
stopWords = WordData[All, "Stopwords"];
lowerNoStopWords = Select[listLower, Not[MemberQ[stopWords, #]] &];
lowerNoStopWords
)
twitterJaccard[txt_] := (
twitterWords = cleanWords[txt];
wordsSagradaFamilia = listOfWords["Sagrada Familia"];
wordsMuseuPicasso = listOfWords["Museu Picasso"];
wordsParkGuell = listOfWords["Park Güell"];
wordsHardRockCafe = listOfWords["Hard Rock Cafe"];
wordsCampNou = listOfWords["Camp Nou"];
jaccardSagradaFamilia = jaccard[twitterWords, wordsSagradaFamilia];
jaccardMuseuPicasso = jaccard[twitterWords, wordsMuseuPicasso];
jaccardParkGuell = jaccard[twitterWords, wordsParkGuell];
jaccardHardRockCafe = jaccard[twitterWords, wordsHardRockCafe];
jaccardCampNou = jaccard[twitterWords, wordsCampNou];
jaccardIndices = {
jaccardSagradaFamilia,
jaccardMuseuPicasso,
jaccardParkGuell,
jaccardHardRockCafe,
jaccardCampNou
}
)
Note that they created a function called jaccard which I think it is equivalent to the built in function called JaccardDissimilarity.
Finally they embedded the code in Python as I showed earlier with EmbedCode function.
class WolframCloud:
def wolfram_cloud_call(self, **args):
arguments = dict([(key, arg) for key, arg in args.iteritems()])
result = urlopen("http://www.wolframcloud.com/objects/e41033e5-9612-4e54-b523-ad886925f1e", urlencode(arguments))
return result.read()
def call(self, text):
textresult = self.wolfram_cloud_call(text=text)
return textresult
For more details you can find the source code in Github here: https://github.com/adamszewe/HackUPC-Wolfram