Aiming at the challenges of selecting periodic features of ionospheric spherical harmonic functions and the multitude of influencing factors, this paper establishes an ionospheric total electron content (TEC) forecasting mode—semiparametric-spherical harmonic-rule learning (Semi-SH-RL), which integrates semi-parametric methods with rule learning. Firstly, rule learning is introduced to construct rule sets and constraint sets based on prior knowledge, enabling precise extraction of ionospheric periods. Secondly, a self-attention mechanism and a pruning layer are incorporated to optimize feature weights and eliminate redundant periods, thereby obtaining the periodic terms of ionospheric spherical harmonic functions. Then, to mitigate the impact of model computational errors and window width parameters, a semi-parametric varying-coefficient spherical harmonic function model is established by considering both the estimated periodic terms and window width parameters. Finally, the applicability of the proposed theory is validated using six years of data from the Center for Orbit Determination in Europe (CODE). The results show that the improved rule-learning neural network can capture eight-layer monthly and five-layer daily periodic features, effectively decompose periods and reduce noise, and improve the rule-learning neural network model and the selection of periods by assigning weights through the self-attention mechanism after obtaining pruned features. Semi-SH-RL is compared with quadratic programming (QP), CODE'S 1-day predicted GIM (C1PG), long short-term memory (LSTM), semiparametric-spherical harmonic (Semi-SH), semiparametric-spherical harmonic-auto-regressive model (Semi-SH-AR), and Semi-SH-LSTM. In terms of latitude, the mean improvement rates of residuals less than 0.5 TECU are 41.01%, 28.01%, 22.40%, 11.02%, 12.63%, and 8.30%, respectively. Semi-SH-RL model achieves average single-day forecasting errors within 1, 3, and 5 TECU for 62.61%, 94.95%, and 98.97% respectively, outperforming other comparative models. For a five-day sliding forecast, the model shows improvements of 4.80% and 4.54% over the Semi-SH and Semi-SH-AR models. The periodic features of the model exhibit consistency across spherical harmonic functions of different orders, and the periodic values converge in accuracy after a single round of rule learning, significantly enhancing forecasting efficiency.