Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
subalterngames committed Jul 15, 2018
0 parents commit 08426e6
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dist/*
venv/*
.idea/*
*.backup
json_exporter.py
cultures.py
Output/*
Binary file added Images/lyria.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/pharostine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/python_install.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Input/lyria.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"culture": {
"visigothic": 3,
"saxon": 3,
"suebi": 3
},
"name": "lyria"
}
11 changes: 11 additions & 0 deletions Input/pharostine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"culture": {
"assyrian": 1,
"georgian": 1,
"alan": 1,
"greek": 15,
"roman": 8,
"armenian": 8
},
"name": "pharostine"
}
186 changes: 186 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@

# Overview
Cultural Place Name Generator randomly generates city and regional names based on real-life cities. Want a fantasy city name that sounds English but with some French and Italian thrown in? That's what this program does.

Here is "Lyria", a blend of Visigothic, Saxon, and Suebi:

![Lyria](Images/Lyria.png)

And here is "Pharostine", a blend of Assyrian, Georgian, Alan, Greek, Roman, and Armenian:

![Lyria](Images/Pharostine.png)

# About this manual
This manual is intended for _non-programmers_. If you're a non-programmer, this all might appear a little intimidating. That's OK. I promise it looks tougher to use than it actually is. I'm going to walk you through installing and using the program. Have confidence in your own abilities! It'll be great!

# License
See [license.txt](license.txt)

The content of `provinces.json` was scraped from the data files of the video game Crusader Kings II.

# Installation
OK. Deep breath. There's a lot of steps. I promise it'll be fine.

## 1. Install Python 3
Grab it [here](https://www.python.org/downloads/) (Click the big yellow button).

When installing, be sure to _Add Python to PATH_ (the checkbox at the very bottom).
![The Python path checkbox is at the bottom of the dialogue box](Images/python_install.png)

### What is Python?
Python is a programming language. I made this software in Python. Python is a good tool for some things and not a good tool for other things. It's a _great_ tool for doing zany stuff with words.

I could _compile_ it into a .exe or .app, but I don't think it's worth it--for example, I don't own a Mac, so I would have no way to know if it actually works on OS X. If I just leave it as Python code, I can be sure it'll work for you.

## 2. Open up the terminal
In Windows, go to Start, click on the search dialogue, type in `cmd`, and press enter.

In OS X, go to finder, type in `terminal`, and press enter.

Congrats! You're in the Matrix. The terminal looks way scarier than it actually is.

### How to read terminal instructions
Whenever you read "type `some instructions`" that always means: type those instructions _in the terminal_ and then _press enter._

Whenever you read something like "type `cd <path/to/file>`" don't type the \< or the \>, and replace path/to/file with the actual path to the file (for example: `cd c:/users/seth/Cultural_Place_Name_Generator`)

## 3. Install stuff with pip
You just need to have an extra Python thing:
type `pip -3.6 install markovify`

## 4. Download my program
Get it here. Unzip the download.

## 5. Congratulate yourself!
OK you're all set up. Great job!! I knew you could do it.

# Usage

Using Windows Explorer (Windows) or Finder (OS X), navigate to `Cultural_Place_Name_Generator/Input` (I don't know where the folder ``Cultural_Place_Name_Generator` is located; it's wherever you unzipped the download .zip file.)

## Input

I've included a couple sample input files in `Cultural_Name_Place_Generator/Input` They are all `.json` files. You can open them in Notepad on Windows and TextEdit in OS X. They look like this:

```
{
"culture": {
"assyrian": 1,
"georgian": 1,
"alan": 1,
"greek": 15,
"roman": 8,
"armenian": 8
},
"name": "pharostine"
}
```
`name` is the name of the _fantasy_ culture. `culture` is the pre-set names of cultures that can blend together. The number is the `weight`. A higher number means that this culture's place-names will be favored more.

You can use the examples I provided to create your own; just remember to save them to the `Input` folder, and make sure the extension is `.json` instead of `.txt`

See "Cultures" for the list of acceptable cultures.

## Output

Once you have set up your fantasy culture(s), open the terminal.

- type `cd <path/to/Cultural_Place_Name_Generator`
- type `py -3.6 namer.py`

Wait a bit for the terminal prompt to re-appear... that's how you'll know it's done processing.

Go to the `Output` folder. There's your placenames!

- **Settlements** are names of towns or cities
- **Provinces** are names of regions, kingdoms, etc.

# Cultures
These are the accepted names of cultures:

- pommeranian
- manden
- greek
- khazar
- serbian
- persian
- saka
- assamese
- alan
- norse
- polish
- sindhi
- hindustani
- egyptian_arabic
- telugu
- lappish
- karluk
- sumpa
- occitan
- bohemian
- hungarian
- komi
- welsh
- assyrian
- khanty
- sinhala
- avar
- gujurati
- breton
- croatian
- old_saxon
- romanian
- georgian
- cuman
- ethiopian
- bulgarian
- baloch
- german
- tocharian
- kannada
- lombard
- maghreb_arabic
- turkish
- nepali
- bengali
- panjabi
- tangut
- irish
- ugricbaltic
- marathi
- basque
- suebi
- pictish
- bolghar
- lithuanian
- visigothic
- kirghiz
- severian
- lettigallish
- nubian
- bedouin_arabic
- oriya
- levantine_arabic
- samoyed
- ilmenian
- mordvin
- tamil
- italian
- afghan
- sogdian
- zhangzhung
- prussian
- pecheneg
- saxon
- han
- old_frankish
- bodpa
- finnish
- volhynian
- frisian
- somali
- kurdish
- armenian
- uyghur
- rajput
7 changes: 7 additions & 0 deletions license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2018 Subaltern Games, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
91 changes: 91 additions & 0 deletions namer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from os import getcwd, listdir, mkdir
from os.path import isdir
from json import loads
import markovify


# Returns all provinces and their settlements with a given culture.
def get_culture(culture):
with open(getcwd() + "/provinces.json", 'rt') as f:
provinces = loads(f.read())
c_p = dict()
for key in provinces.keys():
if provinces[key]["culture"] == culture:
c_p.update({key: provinces[key]})
return c_p


# Returns all provinces with a given culture.
def get_provinces(culture):
provinces = []
for key in culture.keys():
p = get_culture(key).keys()
for i in range(culture[key]):
provinces.extend(p)
return provinces


# Returns all settlements with a given culture.
def get_settlements(culture):
settlements = []
for key in culture.keys():
s = get_culture(key)
for k in s.keys():
settlements.extend(s[k]["settlements"])
return settlements


# Turns lines into sentences that markovify can parse.
def get_text_model(lines):
for i in range(len(lines)):
line = ""
for j in range(len(lines[i])):
line += lines[i][j]
if j < len(lines[i]) - 1:
line += " "
else:
line += "."
lines[i] = line
text_model = markovify.Text(lines, state_size=2)
return text_model


# Returns a scrambled markovified word.
def markov(text_model):
sentence = None
count = 0
while sentence == None and count < 10:
sentence = text_model.make_sentence()
count += 1
if sentence == None:
return None, False
else:
# Turn the sentence into a word
return sentence.replace(" ", "").replace(".", "").title(), True


# Generate gibberish.
def generate(filename, filename_suffix, dataset):
text_model = get_text_model(dataset)
added = set()
generated = []
for i in range(500):
item, real = markov(text_model)
if real and item not in added:
generated.append(item + "\n")
added.update({item})
directory = getcwd() + "/Output"
if not isdir(directory):
mkdir(directory)
with open(directory + "/" + filename + "_" + filename_suffix + ".txt", "wt") as f:
f.writelines(generated)


# Load the stored cultural blends and generate some names.
for f in listdir(getcwd() + "/Input"):
with open(getcwd() + "/Input/" + f, "rt") as j:
# Get the saved cultural blend.
json_culture = loads(j.read())
# Generate names of provinces and settlements.
generate(json_culture["name"], "provinces", get_provinces(json_culture["culture"]))
generate(json_culture["name"], "settlements", get_settlements(json_culture["culture"]))
1 change: 1 addition & 0 deletions provinces.json

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions provinces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from os import listdir, getcwd
from json import dumps

provinces = dict()

directory = "c:/program files (x86)/Steam/steamapps/common/Crusader Kings II/history/provinces"

for f in listdir(directory):
with open(directory + "/" + f, 'rt') as prov:
lines = prov.readlines()
title = ""
culture = ""
settlements = set()
for line in lines:
if line.startswith("title"):
title = line.split("c_")[1].strip().replace("_", " ").title()
elif (line.endswith("temple\n") or line.endswith("city\n") or line.endswith("castle\n")) and "{" not in line:
s = line.split("=")[0].split("b_")[1].strip().replace("_", " ").title()
settlements.update({s})
elif line.startswith("culture"):
culture = line.split(" = ")[1].strip()
settlements = list(settlements)
provinces.update({title: {"settlements": settlements, "culture": culture}})

with open(getcwd() + "/provinces.json", "wt") as output:
output.write(dumps(provinces))

0 comments on commit 08426e6

Please sign in to comment.