Kotlin port
This commit is contained in:
parent
d7b5647783
commit
d7392ce856
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
swot
|
||||
8
.idea/artifacts/swot_jar.xml
generated
Normal file
8
.idea/artifacts/swot_jar.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="swot.jar">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/</output-path>
|
||||
<root id="archive" name="swot.jar.jar">
|
||||
<element id="module-output" name="swot" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
23
.idea/compiler.xml
generated
Normal file
23
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
3
.idea/copyright/profiles_settings.xml
generated
Normal file
3
.idea/copyright/profiles_settings.xml
generated
Normal file
@ -0,0 +1,3 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
||||
5
.idea/encodings.xml
generated
Normal file
5
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
</project>
|
||||
|
||||
11
.idea/libraries/KotlinJavaRuntime.xml
generated
Normal file
11
.idea/libraries/KotlinJavaRuntime.xml
generated
Normal file
@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime">
|
||||
<CLASSES>
|
||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-runtime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-runtime-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
13
.idea/misc.xml
generated
Normal file
13
.idea/misc.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="SvnConfiguration" myUseAcceleration="nothing">
|
||||
<configuration>$USER_HOME$/.subversion</configuration>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
9
.idea/modules.xml
generated
Normal file
9
.idea/modules.xml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/swot.iml" filepath="$PROJECT_DIR$/swot.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
5
.idea/scopes/scope_settings.xml
generated
Normal file
5
.idea/scopes/scope_settings.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="DependencyValidationManager">
|
||||
<state>
|
||||
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||
</state>
|
||||
</component>
|
||||
125
.idea/uiDesigner.xml
generated
Normal file
125
.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,125 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
7
.idea/vcs.xml
generated
Normal file
7
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
4
lib/domains/blacklist.txt
Normal file
4
lib/domains/blacklist.txt
Normal file
@ -0,0 +1,4 @@
|
||||
si.edu
|
||||
america.edu
|
||||
californiacolleges.edu
|
||||
maricopa.edu
|
||||
162
lib/domains/tlds.txt
Normal file
162
lib/domains/tlds.txt
Normal file
@ -0,0 +1,162 @@
|
||||
ac.ae
|
||||
ac.at
|
||||
ac.bd
|
||||
ac.be
|
||||
ac.cn
|
||||
ac.cr
|
||||
ac.cy
|
||||
ac.fj
|
||||
ac.gg
|
||||
ac.gn
|
||||
ac.id
|
||||
ac.il
|
||||
ac.in
|
||||
ac.ir
|
||||
ac.jp
|
||||
ac.ke
|
||||
ac.kr
|
||||
ac.ma
|
||||
ac.me
|
||||
ac.mu
|
||||
ac.mw
|
||||
ac.mz
|
||||
ac.ni
|
||||
ac.nz
|
||||
ac.om
|
||||
ac.pa
|
||||
ac.pg
|
||||
ac.pr
|
||||
ac.rs
|
||||
ac.ru
|
||||
ac.rw
|
||||
ac.sz
|
||||
ac.th
|
||||
ac.tz
|
||||
ac.ug
|
||||
ac.uk
|
||||
ac.yu
|
||||
ac.za
|
||||
ac.zm
|
||||
ac.zw
|
||||
ed.ao
|
||||
ed.cr
|
||||
ed.jp
|
||||
edu
|
||||
edu.af
|
||||
edu.al
|
||||
edu.ar
|
||||
edu.au
|
||||
edu.az
|
||||
edu.ba
|
||||
edu.bb
|
||||
edu.bd
|
||||
edu.bh
|
||||
edu.bi
|
||||
edu.bn
|
||||
edu.bo
|
||||
edu.br
|
||||
edu.bs
|
||||
edu.bt
|
||||
edu.bz
|
||||
edu.ck
|
||||
edu.cn
|
||||
edu.co
|
||||
edu.cu
|
||||
edu.do
|
||||
edu.dz
|
||||
edu.ec
|
||||
edu.ee
|
||||
edu.eg
|
||||
edu.er
|
||||
edu.es
|
||||
edu.et
|
||||
edu.ge
|
||||
edu.gh
|
||||
edu.gr
|
||||
edu.gt
|
||||
edu.hk
|
||||
edu.hn
|
||||
edu.ht
|
||||
edu.in
|
||||
edu.iq
|
||||
edu.jm
|
||||
edu.jo
|
||||
edu.kg
|
||||
edu.kh
|
||||
edu.kn
|
||||
edu.kw
|
||||
edu.ky
|
||||
edu.kz
|
||||
edu.la
|
||||
edu.lb
|
||||
edu.lr
|
||||
edu.lv
|
||||
edu.ly
|
||||
edu.me
|
||||
edu.mg
|
||||
edu.mk
|
||||
edu.ml
|
||||
edu.mm
|
||||
edu.mn
|
||||
edu.mo
|
||||
edu.mt
|
||||
edu.mv
|
||||
edu.mw
|
||||
edu.mx
|
||||
edu.my
|
||||
edu.ni
|
||||
edu.np
|
||||
edu.om
|
||||
edu.pa
|
||||
edu.pe
|
||||
edu.ph
|
||||
edu.pk
|
||||
edu.pl
|
||||
edu.pr
|
||||
edu.ps
|
||||
edu.pt
|
||||
edu.pw
|
||||
edu.py
|
||||
edu.qa
|
||||
edu.rs
|
||||
edu.ru
|
||||
edu.sa
|
||||
edu.sc
|
||||
edu.sd
|
||||
edu.sg
|
||||
edu.sh
|
||||
edu.sl
|
||||
edu.sv
|
||||
edu.sy
|
||||
edu.tr
|
||||
edu.tt
|
||||
edu.tw
|
||||
edu.ua
|
||||
edu.uy
|
||||
edu.ve
|
||||
edu.vn
|
||||
edu.ws
|
||||
edu.ye
|
||||
edu.zm
|
||||
es.kr
|
||||
g12.br
|
||||
hs.kr
|
||||
ms.kr
|
||||
sc.kr
|
||||
sc.ug
|
||||
sch.ae
|
||||
sch.gg
|
||||
sch.id
|
||||
sch.ir
|
||||
sch.je
|
||||
sch.jo
|
||||
sch.lk
|
||||
sch.ly
|
||||
sch.my
|
||||
sch.om
|
||||
sch.ps
|
||||
sch.sa
|
||||
sch.uk
|
||||
school.nz
|
||||
school.za
|
||||
vic.edu.au
|
||||
72
lib/swot.rb
72
lib/swot.rb
@ -1,72 +0,0 @@
|
||||
require "public_suffix"
|
||||
require "naughty_or_nice"
|
||||
require_relative "swot/academic_tlds"
|
||||
|
||||
class Swot < NaughtyOrNice
|
||||
VERSION = "0.3.0"
|
||||
|
||||
# These are domains that snuck into the edu registry,
|
||||
# but don't pass the education sniff test
|
||||
# Note: validated domain must not end with the blacklisted string
|
||||
BLACKLIST = %w(
|
||||
si.edu
|
||||
america.edu
|
||||
).freeze
|
||||
|
||||
class << self
|
||||
alias_method :is_academic?, :valid?
|
||||
alias_method :academic?, :valid?
|
||||
|
||||
def get_institution_name(text)
|
||||
Swot.new(text).institution_name
|
||||
end
|
||||
alias_method :school_name, :get_institution_name
|
||||
|
||||
def domains_path
|
||||
@domains_path ||= File.expand_path "domains", File.dirname(__FILE__)
|
||||
end
|
||||
end
|
||||
|
||||
# Figure out if an email or domain belongs to academic institution.
|
||||
#
|
||||
# Returns true if the domain name belongs to an academic institution;
|
||||
# false otherwise.
|
||||
def valid?
|
||||
if domain.nil?
|
||||
false
|
||||
elsif BLACKLIST.any? { |d| domain =~ /(\A|\.)#{Regexp.escape(d)}\z/ }
|
||||
false
|
||||
elsif ACADEMIC_TLDS.include?(domain_parts.tld)
|
||||
true
|
||||
elsif academic_domain?
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# Figure out the institution name based on the email address/domain.
|
||||
#
|
||||
# Returns a string with the institution name; nil if nothing is found.
|
||||
def institution_name
|
||||
@institution_name ||= File.read(file_path, :mode => "rb", :external_encoding => "UTF-8").strip
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
alias_method :school_name, :institution_name
|
||||
alias_method :name, :institution_name
|
||||
|
||||
# Figure out if a domain name is a know academic institution.
|
||||
#
|
||||
# Returns true if the domain name belongs to a known academic institution;
|
||||
# false otherwise.
|
||||
def academic_domain?
|
||||
@academic_domain ||= File.exists?(file_path)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def file_path
|
||||
@file_path ||= File.join(Swot::domains_path, domain_parts.domain.to_s.split(".").reverse) + ".txt"
|
||||
end
|
||||
end
|
||||
@ -1,169 +0,0 @@
|
||||
require 'set'
|
||||
|
||||
class Swot < NaughtyOrNice
|
||||
# These top-level domains are guaranteed to be academic institutions.
|
||||
ACADEMIC_TLDS = %w(
|
||||
ac.ae
|
||||
ac.at
|
||||
ac.bd
|
||||
ac.be
|
||||
ac.cn
|
||||
ac.cr
|
||||
ac.cy
|
||||
ac.fj
|
||||
ac.gg
|
||||
ac.gn
|
||||
ac.id
|
||||
ac.il
|
||||
ac.in
|
||||
ac.ir
|
||||
ac.jp
|
||||
ac.ke
|
||||
ac.kr
|
||||
ac.ma
|
||||
ac.me
|
||||
ac.mu
|
||||
ac.mw
|
||||
ac.mz
|
||||
ac.ni
|
||||
ac.nz
|
||||
ac.om
|
||||
ac.pa
|
||||
ac.pg
|
||||
ac.pr
|
||||
ac.rs
|
||||
ac.ru
|
||||
ac.rw
|
||||
ac.sz
|
||||
ac.th
|
||||
ac.tz
|
||||
ac.ug
|
||||
ac.uk
|
||||
ac.yu
|
||||
ac.za
|
||||
ac.zm
|
||||
ac.zw
|
||||
ed.ao
|
||||
ed.cr
|
||||
ed.jp
|
||||
edu
|
||||
edu.af
|
||||
edu.al
|
||||
edu.ar
|
||||
edu.au
|
||||
edu.az
|
||||
edu.ba
|
||||
edu.bb
|
||||
edu.bd
|
||||
edu.bh
|
||||
edu.bi
|
||||
edu.bn
|
||||
edu.bo
|
||||
edu.br
|
||||
edu.bs
|
||||
edu.bt
|
||||
edu.bz
|
||||
edu.ck
|
||||
edu.cn
|
||||
edu.co
|
||||
edu.cu
|
||||
edu.do
|
||||
edu.dz
|
||||
edu.ec
|
||||
edu.ee
|
||||
edu.eg
|
||||
edu.er
|
||||
edu.es
|
||||
edu.et
|
||||
edu.ge
|
||||
edu.gh
|
||||
edu.gr
|
||||
edu.gt
|
||||
edu.hk
|
||||
edu.hn
|
||||
edu.ht
|
||||
edu.in
|
||||
edu.iq
|
||||
edu.jm
|
||||
edu.jo
|
||||
edu.kg
|
||||
edu.kh
|
||||
edu.kn
|
||||
edu.kw
|
||||
edu.ky
|
||||
edu.kz
|
||||
edu.la
|
||||
edu.lb
|
||||
edu.lr
|
||||
edu.lv
|
||||
edu.ly
|
||||
edu.me
|
||||
edu.mg
|
||||
edu.mk
|
||||
edu.ml
|
||||
edu.mm
|
||||
edu.mn
|
||||
edu.mo
|
||||
edu.mt
|
||||
edu.mv
|
||||
edu.mw
|
||||
edu.mx
|
||||
edu.my
|
||||
edu.ni
|
||||
edu.np
|
||||
edu.om
|
||||
edu.pa
|
||||
edu.pe
|
||||
edu.ph
|
||||
edu.pk
|
||||
edu.pl
|
||||
edu.pr
|
||||
edu.ps
|
||||
edu.pt
|
||||
edu.pw
|
||||
edu.py
|
||||
edu.qa
|
||||
edu.rs
|
||||
edu.ru
|
||||
edu.sa
|
||||
edu.sc
|
||||
edu.sd
|
||||
edu.sg
|
||||
edu.sh
|
||||
edu.sl
|
||||
edu.sv
|
||||
edu.sy
|
||||
edu.tr
|
||||
edu.tt
|
||||
edu.tw
|
||||
edu.ua
|
||||
edu.uy
|
||||
edu.ve
|
||||
edu.vn
|
||||
edu.ws
|
||||
edu.ye
|
||||
edu.zm
|
||||
es.kr
|
||||
g12.br
|
||||
hs.kr
|
||||
ms.kr
|
||||
sc.kr
|
||||
sc.ug
|
||||
sch.ae
|
||||
sch.gg
|
||||
sch.id
|
||||
sch.ir
|
||||
sch.je
|
||||
sch.jo
|
||||
sch.lk
|
||||
sch.ly
|
||||
sch.my
|
||||
sch.om
|
||||
sch.ps
|
||||
sch.sa
|
||||
sch.uk
|
||||
school.nz
|
||||
school.za
|
||||
vic.edu.au
|
||||
).to_set.freeze
|
||||
end
|
||||
58
src/swot/Swot.kt
Normal file
58
src/swot/Swot.kt
Normal file
@ -0,0 +1,58 @@
|
||||
package swot
|
||||
|
||||
fun isAcademic(emailOrDomain: String): Boolean {
|
||||
val parts = domainParts(emailOrDomain)
|
||||
return !isBlacklisted(parts) && (isUnderTLD(parts) || findSchoolNames(parts).isNotEmpty())
|
||||
}
|
||||
|
||||
fun findSchoolNames(emailOrDomain: String): List<String> {
|
||||
return findSchoolNames(domainParts(emailOrDomain))
|
||||
}
|
||||
|
||||
fun isUnderTLD(parts: List<String>): Boolean {
|
||||
return checkSet(Resources.tlds, parts)
|
||||
}
|
||||
|
||||
fun isBlacklisted(parts: List<String>): Boolean {
|
||||
return checkSet(Resources.blackList, parts)
|
||||
}
|
||||
|
||||
private object Resources {
|
||||
val tlds = readList("/tlds.txt") ?: error("Cannot find /tlds.txt")
|
||||
val blackList = readList("/blacklist.txt") ?: error("Cannot find /blacklist.txt")
|
||||
|
||||
fun readList(resource: String) : Set<String>? {
|
||||
return javaClass.getResourceAsStream(resource)?.reader()?.buffered()?.lines()?.toHashSet()
|
||||
}
|
||||
}
|
||||
|
||||
private fun findSchoolNames(parts: List<String>): List<String> {
|
||||
val resourcePath = StringBuilder("")
|
||||
for (part in parts) {
|
||||
resourcePath.append('/').append(part)
|
||||
val school = Resources.readList("${resourcePath}.txt")
|
||||
if (school != null) {
|
||||
return school.toList()
|
||||
}
|
||||
}
|
||||
|
||||
return arrayListOf()
|
||||
}
|
||||
|
||||
private fun domainParts(emailOrDomain: String): List<String> {
|
||||
return emailOrDomain.toLowerCase().substringAfter('@').split('.').reverse()
|
||||
}
|
||||
|
||||
private fun checkSet(set: Set<String>, parts: List<String>): Boolean {
|
||||
val subj = StringBuilder()
|
||||
for (part in parts) {
|
||||
subj.append(part)
|
||||
if (set.contains(subj.toString())) return true
|
||||
subj.append('.')
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(isAcademic("max@maricopa.edu"))
|
||||
}
|
||||
14
swot.iml
Normal file
14
swot.iml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/lib/domains" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user