# Finding paths between Wikipedia articles

**URL:** <https://discourse.elm-lang.org/t/finding-paths-between-wikipedia-articles/1442>\
**Category:** Show and Tell\
**Created:** [June 29, 2018, 12:25pm UTC](https://discourse.elm-lang.org/t/finding-paths-between-wikipedia-articles/1442 "2018-06-29T12:25:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fizwidget](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/fizwidget/32/920_2.png) [@fizwidget](https://discourse.elm-lang.org/u/fizwidget)\
**Post date:** [June 29, 2018, 12:25pm UTC](https://discourse.elm-lang.org/t/finding-paths-between-wikipedia-articles/1442/1 "2018-06-29T12:25:21Z")

</div>

Hi everyone!

I’ve been working on a small project recently to teach myself Elm: a website that finds paths between Wikipedia articles. As an example, a path from “Buzz Lightyear” to “R2-D2” might be:

_Buzz Lightyear → Lego → Star Wars → R2-D2_

…meaning the “Buzz Lightyear” article links to the “Lego” article, which then links to “Star Wars”, and so on.

Other people have built similar things before, with [this](https://www.sixdegreesofwikipedia.com) perhaps being the most impressive example, but I haven’t seen an Elm implementation yet (let me know if there is one!).

You can play with my version here:  
[https://fizwidget.github.io/wiki-path](https://fizwidget.github.io/wiki-path)

And browse the code here:

> **[fizwidget/wiki-path](https://github.com/fizwidget/wiki-path)**
>
> Find paths between Wikipedia articles. Contribute to fizwidget/wiki-path development by creating an account on GitHub.

This is the first time I’ve written anything in a purely functional language, so feedback on the code is definitely welcome! Have I done things in an idiomatic way, or are there nicer ways of modelling this kind of problem?

Also, any recommendations for how to nicely visualise the pathfinding process?

Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![john-kelly](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/john-kelly/32/69_2.png) [@john-kelly](https://discourse.elm-lang.org/u/john-kelly)\
**Post date:** [June 29, 2018, 5:17pm UTC](https://discourse.elm-lang.org/t/finding-paths-between-wikipedia-articles/1442/2 "2018-06-29T17:17:57Z")

</div>

This is pretty cool. I once had to do something similar to this for a job interview.

One piece of feedback that I have re: the code is that you may want to reconsider the way you’ve split up your files / logic. It seems to be pretty common to split things up into View.elm, Model.elm, Update.elm, and etc, however, (based on my understanding) it’s _not_ the recommended path.

Don’t be afraid to have files which _feel_ a little bigger than what you’re used to. Elm will help you keep everything in check! For starters, I’d try/experiment moving the View.elm, Update.elm, and Model.elm into Main.elm

For a more in depth look / explanation of this idea, check out this talk: [https://m.youtube.com/watch?v=XpDsk374LDE](https://m.youtube.com/watch?v=XpDsk374LDE)

---

<div class="post-metadata">

**Author:** ![joakin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/joakin/32/171_2.png) [@joakin](https://discourse.elm-lang.org/u/joakin)\
**Post date:** [June 29, 2018, 7:13pm UTC](https://discourse.elm-lang.org/t/finding-paths-between-wikipedia-articles/1442/3 "2018-06-29T19:13:11Z")

</div>

Very cool.

I had a look but I found it a bit hard to read the code with so many small files separated by messages/update/view/etc.

I’d suggest if you can to have a read at the [API etiquette](https://www.mediawiki.org/wiki/API:Etiquette) and implement some of the suggestions, like for example setting a specific user agent on your queries 😄

---

<div class="post-metadata">

**Author:** ![fizwidget](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/fizwidget/32/920_2.png) [@fizwidget](https://discourse.elm-lang.org/u/fizwidget)\
**Post date:** [June 30, 2018, 12:21am UTC](https://discourse.elm-lang.org/t/finding-paths-between-wikipedia-articles/1442/4 "2018-06-30T00:21:16Z")

</div>

Thanks for the feedback @john-kelly & @joakin! 🙂

Yup, I guess I did go overboard with the number of files 😅. I’m used to React/Redux conventions, where having separate files for actions/reducers/components/etc is typical.

I do feel like the “hard to read” problem mostly goes away with an editor or IDE, as definitions are then all a single-click away. But it would certainly be nicer if it were readable without the help of tools like that 👍

If I collapse pages down to a single module each, I’ll have to re-think how transitions between them work. With the current approach, one page can import another page’s `Init` module, which it can use to transition to that page. E.g. `Setup.Update` calls `Pathfinding.Init` to kick off pathfinding, and `Pathfinding.Update` calls `Finished.Init` when it successfully finds a path.

This approach allows the top-level update function to be trivial, as it doesn’t have to worry about transitions between pages. When I consolidate the pages down to one module each, I’ll have to add transition logic to the top-level to avoid circular dependencies between pages? 🤔 And pages will also need a way of notifying the top-level when they wish to initiate a transition.

I’ll have more of a think about that…would bringing in a proper routing library solve this problem? I haven’t looked into routing much yet.

And thanks for the API etiquette link @joakin, there’s definitely some improvements I can make there! Requesting multiple articles in a single call (instead of n separate calls) is on the to-do list for example.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [July 10, 2018, 12:21am UTC](https://discourse.elm-lang.org/t/finding-paths-between-wikipedia-articles/1442/5 "2018-07-10T00:21:16Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
