summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-08-25 09:02:54 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-08-25 10:09:36 (GMT)
commitf4d2b6a176ff6228af87a785a07a8a232c1c989c (patch)
tree2dc8b84a97f7b936a3e62a05460b2548b0d177a2
parent7d1c80961416ec227f2a0b24aa79e258241cbcdb (diff)
Improvements to the name resolver type interpreter
1. Allow for case insensitive comparisons 2. Rewrite code in a more readable manner using QStringList to store synonymous type codes. 3. Use a C++11 lambda to compare strings. Makes for more readable code. 4. Add more synonymous type strings.
-rw-r--r--kstars/tools/nameresolver.cpp63
-rw-r--r--kstars/tools/nameresolver.h5
2 files changed, 43 insertions, 25 deletions
diff --git a/kstars/tools/nameresolver.cpp b/kstars/tools/nameresolver.cpp
index c517959..45a3140 100644
--- a/kstars/tools/nameresolver.cpp
+++ b/kstars/tools/nameresolver.cpp
@@ -178,7 +178,7 @@ bool NameResolver::NameResolverInternals::sesameResolver( class CatalogEntryData
// // QUrl( QString( "http://simbad.u-strasbg.fr/simbad/sim-script?script=output%20console=off%20script=off%0Aformat%20object%20%22%25DIM%22%0A" ) + data.name );
// }
-SkyObject::TYPE NameResolver::NameResolverInternals::interpretObjectType( const QString &typeString ) {
+SkyObject::TYPE NameResolver::NameResolverInternals::interpretObjectType( const QString &typeString, bool caseSensitive ) {
// FIXME: Due to the quirks of Sesame (SIMBAD vs NED etc), it
// might be very difficult to discern the type in all cases. The
@@ -190,43 +190,58 @@ SkyObject::TYPE NameResolver::NameResolverInternals::interpretObjectType( const
// See http://cds.u-strasbg.fr/cgi-bin/Otype?IR for Object Classification in SIMBAD
// Highest likelihood is a galaxy of some form, so we process that first
- if( typeString == "G" || typeString == "LIN" || typeString == "AGN"
- || typeString == "GiG" || typeString == "GiC" || typeString == "H2G"
- || typeString == "BiC" || typeString == "GiP" || typeString == "HzG"
- || typeString == "rG" || typeString == "AG?" || typeString == "EmG"
- || typeString == "LSB" || typeString == "SBG" || typeString == "bCG"
- || typeString == "SyG" || typeString == "Sy1" || typeString == "Sy2" ) {
- // this is a galaxy
+ const QString &s = typeString; // To make the code compact
+ Qt::CaseSensitivity cs = ( caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive );
+
+ QStringList galaxyTypes;
+ QStringList galaxyGroupTypes;
+ QStringList openClusterTypes;
+ QStringList radioSourceTypes;
+ galaxyTypes << "G" << "LIN" << "AGN" << "GiG" << "GiC" << "H2G" << "BiC"
+ << "GiP" << "HzG" << "rG" << "AG?" << "EmG" << "LSB" << "SBG"
+ << "bCG" << "SyG" << "Sy1" << "Sy2" << "Gxy";
+
+ galaxyGroupTypes << "GClstr" << "GGroup" << "GPair" << "ClG" << "CGG"
+ << "PaG" << "IG" << "GrG" << "SCG"; // NOTE (FIXME?): Compact groups and pairs of galaxies ar treated like galaxy clusters
+
+ openClusterTypes << "*Cl" << "Cl*" << "OpC" << "As*" << "St*" << "OCl";
+
+ radioSourceTypes << "Rad" << "mR" << "cm" << "mm" << "smm" << "HI" << "rB" << "Mas";
+
+ if ( galaxyTypes.contains( s, cs ) )
return SkyObject::GALAXY;
- }
- // Next possibility is galaxy cluster
- if( typeString == "GClstr" || typeString == "GGroup" || typeString == "GPair"
- || typeString == "ClG" || typeString == "CGG" || typeString == "PaG"
- || typeString == "IG" || typeString == "GrG" || typeString == "SCG" ) { // NOTE (FIXME?): Compact groups and pairs of galaxies ar treated like galaxy clusters
+
+ if ( galaxyGroupTypes.contains( s, cs ) )
return SkyObject::GALAXY_CLUSTER;
- }
- if( typeString == "*Cl" || typeString == "Cl*" || typeString == "OpC" || typeString == "As*" || typeString == "St*" )
+
+ if ( openClusterTypes.contains( s, cs ) )
return SkyObject::OPEN_CLUSTER; // FIXME: NED doesn't distinguish between globular clusters and open clusters!!
- if( typeString == "GlC" )
+
+ auto check = [typeString, cs]( const QString &type ) {
+ return ( !QString::compare( typeString, type, cs ) );
+ };
+
+ if( check( "GlC" ) || check( "GlCl" ) )
return SkyObject::GLOBULAR_CLUSTER;
- if( typeString == "Neb" || typeString == "HII" || typeString == "HH" ) // FIXME: The last one is Herbig-Haro object
+ if( check( "Neb" ) || check( "HII" ) || check( "HH" ) ) // FIXME: The last one is Herbig-Haro object
return SkyObject::GASEOUS_NEBULA;
- if( typeString == "SNR" ) // FIXME: Simbad returns "ISM" for Veil Nebula (Interstellar Medium??)
+ if( check( "SNR" ) ) // FIXME: Simbad returns "ISM" for Veil Nebula (Interstellar Medium??)
return SkyObject::SUPERNOVA_REMNANT;
- if( typeString == "PN" || typeString == "pA*" ) // FIXME: The latter is actually Proto PN
+ if( check( "PN" ) || check( "PNeb" )
+ || check( "PNe" ) || check( "pA*" ) ) // FIXME: The latter is actually Proto PN
return SkyObject::PLANETARY_NEBULA;
if( typeString == "*" )
return SkyObject::CATALOG_STAR;
- if( typeString == "QSO" )
+ if( check( "QSO" ) )
return SkyObject::QUASAR;
- if( typeString == "DNe" || typeString == "glb" ) // The latter is Bok globule
+ if( check( "DN" ) || check( "DNe" )
+ || check( "DNeb" ) || check( "glb" ) ) // The latter is Bok globule
return SkyObject::DARK_NEBULA;
- if( typeString == "Rad" || typeString == "mR" || typeString == "cm" || typeString == "mm"
- || typeString == "smm" || typeString == "HI" || typeString == "rB" || typeString == "Mas" )
+ if ( radioSourceTypes.contains( s, cs ) )
return SkyObject::RADIO_SOURCE;
if( typeString == "**" )
return SkyObject::MULT_STAR;
- if( typeString.contains('*') && typeString != "C?*" )
+ if( typeString.contains('*') && !check( "C?*" ) )
return SkyObject::CATALOG_STAR;
return SkyObject::TYPE_UNKNOWN;
diff --git a/kstars/tools/nameresolver.h b/kstars/tools/nameresolver.h
index ed7df8a..5a5ed36 100644
--- a/kstars/tools/nameresolver.h
+++ b/kstars/tools/nameresolver.h
@@ -80,9 +80,12 @@ namespace NameResolver {
* / other resolvers and attempts to convert it into a
* SkyObject type.
*
+ * @param typeString An abbreviated string containing the type of the object
+ * @param caseSensitive Should we make a case-sensitive check?
+ *
* @return a SkyObject::TYPE.
*/
- SkyObject::TYPE interpretObjectType( const QString &typeString );
+ SkyObject::TYPE interpretObjectType( const QString &typeString, bool caseSensitive = true );
}