Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to remove unnecessary text and lower the command #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions buildsample/Build.AviationSample.cls
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ ClassMethod Build()
}

/// This method enables you to build the sample with a minimum of output to the Terminal.
/// <var>stagingroot</var> is the name of the directory that contains the downloaded files.
/// <var>interactive</var> controls whether this method displays output.
/// <methodname>Build</methodname> calls this method with interactive=1.
/// stagingroot is the name of the directory that contains the downloaded files.
/// interactive controls whether this method displays output.
/// Build calls this method with interactive=1.
ClassMethod run(stagingroot As %String = "", interactive As %Boolean = 0)
{
//repeat this test here in case we go directly to this method
Expand All @@ -56,7 +56,7 @@ ClassMethod run(stagingroot As %String = "", interactive As %Boolean = 0)
return 0
}

//load and compile classes ***************************
// load and compile classes ***************************
set dir=stagingroot_"/cls/" ;works on both Windows and Unix
if '##class(%File).DirectoryExists(dir) {
if interactive {
Expand All @@ -70,7 +70,7 @@ ClassMethod run(stagingroot As %String = "", interactive As %Boolean = 0)
}
do $system.OBJ.LoadDir(dir,"ck",,1)

//load data from exported global ******************************
// Load data from exported global ******************************
if interactive {
write !, "Loading data..."
}
Expand All @@ -84,7 +84,7 @@ ClassMethod run(stagingroot As %String = "", interactive As %Boolean = 0)
}
do $system.OBJ.Load(file)

// execute the setup code in the loaded classes *********************
// Execute the setup code in the loaded classes *********************
if '##class(%Dictionary.CompiledClass).%ExistsId("Aviation.Utils") {
if interactive {
write !!, "Looking for the class Aviation.Utils but it does not exist... Quitting."
Expand Down
214 changes: 6 additions & 208 deletions cls/Aviation/Aircraft.cls
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// Use or operation of this code is subject to acceptance of the license available in the code repository for this code.
/// <p>This class represents the details on aircraft involved in events registered by the
/// <a href="http://www.ntsb.gov/" target="_blank">National Transportation Safety Board</a>.</p>
/// <p><b>Note on the data</b>: The dataset provided in this sample demo is only a lightweight
/// This class represents the details on aircraft involved in events registered by the
/// National Transportation Safety Board.
/// Note on the data</b>: The dataset provided in this sample demo is only a lightweight
/// subset of the full NTSB dataset, which is available from
/// <a href="http://www.ntsb.gov/" target="_blank">http://www.ntsb.gov</a>. This data is supplied
/// here for demonstration purposes only and neither intended nor warranted to be accurate.<br/>
/// Courtesy: National Transportation Safety Board</p>
/// http://www.ntsb.gov. This data is supplied
/// here for demonstration purposes only and neither intended nor warranted to be accurate.
/// Courtesy: National Transportation Safety Board
Class Aviation.Aircraft Extends %Persistent
{

Expand Down Expand Up @@ -139,207 +139,5 @@ Property FlightMedicalType As %Library.String(MAXLEN = 15);

Index PKINDEX On (EventId, AircraftKey) [ PrimaryKey, Unique ];

Storage Default
{
<Data name="AircraftDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>EventId</Value>
</Value>
<Value name="3">
<Value>AircraftKey</Value>
</Value>
<Value name="4">
<Value>RegistrationNumber</Value>
</Value>
<Value name="5">
<Value>Missing</Value>
</Value>
<Value name="6">
<Value>FlightPlan</Value>
</Value>
<Value name="7">
<Value>FlightPlanActivated</Value>
</Value>
<Value name="8">
<Value>Damage</Value>
</Value>
<Value name="9">
<Value>AccidentFire</Value>
</Value>
<Value name="10">
<Value>AccidentExplosion</Value>
</Value>
<Value name="11">
<Value>AircraftManufacturer</Value>
</Value>
<Value name="12">
<Value>AircraftModel</Value>
</Value>
<Value name="13">
<Value>AircraftSeries</Value>
</Value>
<Value name="14">
<Value>AircraftSerialNo</Value>
</Value>
<Value name="15">
<Value>AircraftCertMaxGrossWeight</Value>
</Value>
<Value name="16">
<Value>AircraftCategory</Value>
</Value>
<Value name="17">
<Value>AircraftRegistrationClass</Value>
</Value>
<Value name="18">
<Value>AircraftHomeBuilt</Value>
</Value>
<Value name="19">
<Value>SeatsFlightCrew</Value>
</Value>
<Value name="20">
<Value>SeatsCabinCrew</Value>
</Value>
<Value name="21">
<Value>SeatsPassengers</Value>
</Value>
<Value name="22">
<Value>SeatsTotal</Value>
</Value>
<Value name="23">
<Value>EngineCount</Value>
</Value>
<Value name="24">
<Value>GearType</Value>
</Value>
<Value name="25">
<Value>LastInspectionType</Value>
</Value>
<Value name="26">
<Value>LastInspectionDate</Value>
</Value>
<Value name="27">
<Value>AirFrameHoursSinceLastInspection</Value>
</Value>
<Value name="28">
<Value>AirFrameHours</Value>
</Value>
<Value name="29">
<Value>Owner</Value>
</Value>
<Value name="30">
<Value>OwnerState</Value>
</Value>
<Value name="31">
<Value>OwnerCountry</Value>
</Value>
<Value name="32">
<Value>OperatorIndividual</Value>
</Value>
<Value name="33">
<Value>OperatorName</Value>
</Value>
<Value name="34">
<Value>OperatorState</Value>
</Value>
<Value name="35">
<Value>OperatorCountry</Value>
</Value>
<Value name="36">
<Value>OperatorCode</Value>
</Value>
<Value name="37">
<Value>OwnerCertified</Value>
</Value>
<Value name="38">
<Value>OperatorCertificate</Value>
</Value>
<Value name="39">
<Value>OperatorCertificateNum</Value>
</Value>
<Value name="40">
<Value>OperationScheduled</Value>
</Value>
<Value name="41">
<Value>OperationDomestic</Value>
</Value>
<Value name="42">
<Value>OperationType</Value>
</Value>
<Value name="43">
<Value>FlightType</Value>
</Value>
<Value name="44">
<Value>SecondPilot</Value>
</Value>
<Value name="45">
<Value>DepartureSameAsEvent</Value>
</Value>
<Value name="46">
<Value>DepartureAirportId</Value>
</Value>
<Value name="47">
<Value>DepartureCity</Value>
</Value>
<Value name="48">
<Value>DepartureState</Value>
</Value>
<Value name="49">
<Value>DepartureCountry</Value>
</Value>
<Value name="50">
<Value>DepartureTime</Value>
</Value>
<Value name="51">
<Value>DepartureTimeZone</Value>
</Value>
<Value name="52">
<Value>DestinationSameAsLocal</Value>
</Value>
<Value name="53">
<Value>DestinationAirportId</Value>
</Value>
<Value name="54">
<Value>DestinationCity</Value>
</Value>
<Value name="55">
<Value>DestinationState</Value>
</Value>
<Value name="56">
<Value>DestinationCountry</Value>
</Value>
<Value name="57">
<Value>FlightPhase</Value>
</Value>
<Value name="58">
<Value>ReportedToICAO</Value>
</Value>
<Value name="59">
<Value>EvacuationOccurred</Value>
</Value>
<Value name="60">
<Value>AirFrameHoursSince</Value>
</Value>
<Value name="61">
<Value>FlightSiteSeeing</Value>
</Value>
<Value name="62">
<Value>FlightMedical</Value>
</Value>
<Value name="63">
<Value>FlightMedicalType</Value>
</Value>
</Data>
<DataLocation>{%%PARENT}("Aircraft")</DataLocation>
<DefaultData>AircraftDefaultData</DefaultData>
<ExtentSize>100000</ExtentSize>
<IdLocation>^Aviation.EventC("Aircraft")</IdLocation>
<IndexLocation>^Aviation.AircraftI</IndexLocation>
<StreamLocation>^Aviation.AircraftS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}

29 changes: 15 additions & 14 deletions cls/Aviation/Classification/Aviation.Classification.Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ ClassMethod CreateClassifier() As %Status
quit
}

// create training and test set using a rather random split based on the modulo of the record ID
// Create training and test set using a rather random split based on the modulo of the record ID
// Using the modulo operator ensures we'll get the same results each time (unlike using RandomFilter)
set tTrainingSet = ##class(%iKnow.Filters.SqlFilter).%New(tDomId, "SELECT ':SQL:'||YEAR(EventDate)||':'||EventID AS ExternalID FROM Aviation.Event WHERE (ID # 10) <= 5")
set tTestSet = ##class(%iKnow.Filters.SqlFilter).%New(tDomId, "SELECT ':SQL:'||YEAR(EventDate)||':'||EventID AS ExternalID FROM Aviation.Event WHERE (ID # 10) > 5")

// instantiate builder and configure for use with highest injury
// Instantiate builder and configure for use with highest injury
set tBuilder = ##class(%iKnow.Classification.IKnowBuilder).%New("Aviation Events demo",tTrainingSet)
set tBuilder.TestSet = tTestSet
set tSC = tBuilder.%LoadMetadataCategories("HighestInjury")
quit:$$$ISERR(tSC)

// note that "HighestInjury" is perhaps not that convenient to use as a category, as
// Note that "HighestInjury" is perhaps not that convenient to use as a category, as
// for example, a "HighestInjury=Serious" record could well mention some minor injuries as well.


// populate the model with a few terms
// Populate the model with a few terms
set tSC = tBuilder.%PopulateTerms(50)
quit:$$$ISERR(tSC)
set tSC = tBuilder.%AddEntity("crash site")
quit:$$$ISERR(tSC)
set tSC = tBuilder.%AddTermsFromSQL("SELECT TOP 50 EntityValue AS Term FROM %iKnow_Objects.EntityUnique WHERE DomainID = "_tDomId_" AND EntityValue LIKE '%injur%' ORDER BY CorpusSpread DESC")
quit:$$$ISERR(tSC)

// add more terms as you see fit
// Add more terms as you see fit
// ...


// generate classifier class
// Generate classifier class
set tSC = tBuilder.%CreateClassifierClass("Aviation.Classification.MyClassifier", 1, 1, 1)
quit:$$$ISERR(tSC)

Expand All @@ -66,29 +66,30 @@ ClassMethod OptimizeClassifier() As %Status

set tDomId = $system.iKnow.GetDomainId("Aviation Events demo")

// restore a builder object from our class definition
// Restore a builder object from our class definition
set tSC = ##class(%iKnow.Classification.Builder).%LoadFromDefinition("Aviation.Classification.MyClassifier", .tBuilder)
quit:$$$ISERR(tSC)

// instantiate a builder object
// Instantiate a builder object
set tOptimizer = ##class(%iKnow.Classification.Optimizer).%New()
set tOptimizer.Builder = tBuilder

// load candidate entities
// Load candidate entities
set tSC = ##class(%iKnow.Queries.EntityAPI).GetTopBM25(.tCandidates, tDomId, 1, 200)
quit:$$$ISERR(tSC)
// skip the first 50, as we already added them in ..CreateClassifier()

// Skip the first 50, as we already added them in ..CreateClassifier()
for i=1:1:50 { kill tCandidates(i) }
set tSC = tOptimizer.LoadTermsArray(.tCandidates, 2)
quit:$$$ISERR(tSC)

// fire off the optimization process
// Fire off the optimization process
set tOptimizer.Verbose = 1
set tSC = tOptimizer.Optimize(20)
quit:$$$ISERR(tSC)
write !

// save updated class
// Save updated class
set tSC = tOptimizer.SaveClassifier("Aviation.Classificaton.MyClassifier", 1)
quit:$$$ISERR(tSC)

Expand Down Expand Up @@ -121,15 +122,15 @@ ClassMethod TestClassifier() As %Status
write !,"We got ",tRight," records right out of ",tTotal,!


// retrieve precision and recall metrics for this test result
// Retrieve precision and recall metrics for this test result
set tSC = ##class(%DeepSee.PMML.Utils.TempResult).GetAggregatePrecisionMetrics(tResId,.tPrecision,.tMPrecision,.tRecall,.tMRecall,.tFMeasure,.tMFMeasure)
quit:$$$ISERR(tSC)
write !," micro-AVG macro-AVG"
write !,"Precision: ",$fnumber(tMPrecision,"",2),"% ",$fnumber(tPrecision,"",2),"%"
write !,"Recall: ",$fnumber(tMRecall,"",2),"% ",$fnumber(tRecall,"",2),"%"
write !,"F-measure: ",$fnumber(tMFMeasure,"",2),"% ",$fnumber(tFMeasure,"",2),"%",!

// drop test results
// Drop test results
do ##class(%DeepSee.PMML.Utils).%DropResults(tResId)

} catch (ex) {
Expand Down
Loading